Forums
This topic is locked
form insert to database and to email
04 Sep 2007 17:55:30 deep flow posted:
hi i have created a form that inserts records to a database and sends it to an email,
i now need to get the inserted data into the email ,
i also want a dynamic subject line that gets i.e : $subject :firstname and lastname
how should i do it ?
this is the code of the form:
<?php require_once('../domainname.com/Connections/international.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "" ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "" ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "" ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO contact_form (CustomerID, CustomerFirstName, CustomerLastName, CustomerEmail, CustomerCellphone, CustomerHomePhone, CustomerWorkPhone, CustomerFax, TotalNumber, TotalNumberAdults, TotalNumberChildren, RequestText, Marketing_Source, Newsletter) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['CustomerID'], "int",
GetSQLValueString($HTTP_POST_VARS['CustomerFirstName'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerLastName'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerEmail'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerCellphone'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerHomePhone'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerWorkPhone'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerFax'], "text",
GetSQLValueString($HTTP_POST_VARS['TotalNumber'], "text",
GetSQLValueString($HTTP_POST_VARS['TotalNumberAdults'], "text",
GetSQLValueString($HTTP_POST_VARS['TotalNumberChildren'], "text",
GetSQLValueString($HTTP_POST_VARS['RequestText'], "text",
GetSQLValueString($HTTP_POST_VARS['Marketing_Source'], "text",
GetSQLValueString($HTTP_POST_VARS['Newsletter'], "text");
mysql_select_db($database_international, $international);
$Result1 = mysql_query($insertSQL, $international) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO contact_form (CustomerID, CustomerFirstName, CustomerLastName, CustomerEmail, CustomerCellphone, CustomerHomePhone, CustomerWorkPhone, CustomerFax, TotalNumber, TotalNumberAdults, TotalNumberChildren, RequestText, Marketing_Source, Newsletter) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['CustomerID'], "int",
GetSQLValueString($HTTP_POST_VARS['CustomerFirstName'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerLastName'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerEmail'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerCellphone'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerHomePhone'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerWorkPhone'], "text",
GetSQLValueString($HTTP_POST_VARS['CustomerFax'], "text",
GetSQLValueString($HTTP_POST_VARS['TotalNumber'], "text",
GetSQLValueString($HTTP_POST_VARS['TotalNumberAdults'], "text",
GetSQLValueString($HTTP_POST_VARS['TotalNumberChildren'], "text",
GetSQLValueString($HTTP_POST_VARS['RequestText'], "text",
GetSQLValueString($HTTP_POST_VARS['Marketing_Source'], "text",
GetSQLValueString($HTTP_POST_VARS['Newsletter'], "text");
mysql_select_db($database_international, $international);
$Result1 = mysql_query($insertSQL, $international) or die(mysql_error());
$insertGoTo = "sendemail.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];}header(sprintf("Location: %s", $insertGoTo));}
mysql_select_db($database_international, $international);
$query_RsContactForm = "SELECT * FROM contact_form";
$RsContactForm = mysql_query($query_RsContactForm, $international) or die(mysql_error());
$row_RsContactForm = mysql_fetch_assoc($RsContactForm);
$totalRows_RsContactForm = mysql_num_rows($RsContactForm);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Email Form </title>
</head>
<body>
<form method="POST" name="form1" action="<?php echo $editFormAction; ?>">
<p>
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
</p>
<table align="center">
<tr valign="baseline">
<td nowrap align="right">CustomerID:</td>
<td><input name="CustomerID" type="hidden" id="CustomerID"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerFirstName:</td>
<td><input type="text" name="CustomerFirstName" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerLastName:</td>
<td><input type="text" name="CustomerLastName" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerEmail:</td>
<td><input type="text" name="CustomerEmail" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerCellphone:</td>
<td><input type="text" name="CustomerCellphone" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerHomePhone:</td>
<td><input type="text" name="CustomerHomePhone" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerWorkPhone:</td>
<td><input type="text" name="CustomerWorkPhone" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerFax:</td>
<td><input type="text" name="CustomerFax" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">TotalNumber:</td>
<td><input type="text" name="TotalNumber" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">TotalNumberAdults:</td>
<td><input type="text" name="TotalNumberAdults" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">TotalNumberChildren:</td>
<td><input type="text" name="TotalNumberChildren" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">RequestText:</td>
<td> <textarea name="RequestText" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Marketing_Source:</td>
<td><input type="text" name="Marketing_Source" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Newsletter:</td>
<td><input type="text" name="Newsletter" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert Record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($RsContactForm);
?>
<?php
// multiple recipients
$to = ' ' . ', '; // note the comma
$to .= ' ';
// subject
$subject = $_POST["CategoryName"];
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<table align="center">
<tr valign="baseline">
<td nowrap align="right">CustomerID:</td>
<td>CustomerID</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerFirstName:</td>
<td>< tomerFirstName'</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerLastName:</td>
<td> CustomerLastName </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerEmail:</td>
<td> CustomerEmail </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerCellphone:</td>
<td>CustomerCellphone </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerHomePhone:</td>
<td>CustomerHomePhone </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerWorkPhone:</td>
<td>CustomerWorkPhone </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">CustomerFax:</td>
<td>CustomerFax: </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">TotalNumber:</td>
<td>TotalNumber</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">TotalNumberAdults:</td>
<td>TotalNumberAdults: </td>
</tr>
<tr valign="baseline">
<td>TotalNumberChildren</td>
<td>TotalNumberChildren </td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">RequestText:</td>
<td> RequestText </textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Marketing_Source:</td>
<td>Marketing_Source </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Newsletter:</td>
<td>Newsletter </td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary < >, Kelly < >' . "\r\n";
$headers .= 'From: Birthday Reminder < >' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
Replies
Replied 09 Sep 2007 15:35:14
09 Sep 2007 15:35:14 deep flow replied:
BUMP!!
guys i would be most appreciative for an answer if you got one
thx
guys i would be most appreciative for an answer if you got one
thx