PDA

View Full Version : How do I get a copy of submitted database info via email?


webgeek247
07-18-2006, 11:31 AM
Hi i am trying to create a test form whereby the information gets stored on the database and also displays the database info on the page. But I would also like to get a copy of what is submitted to my email address. Is this possible?. Here is my code:


<?php require_once('Connections/mySql.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO textform (name, email, address, age) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['age'], "int"));

mysql_select_db($database_mySql, $mySql);
$Result1 = mysql_query($insertSQL, $mySql) or die(mysql_error());
}

$maxRows_test = 5;
$pageNum_test = 0;
if (isset($_GET['pageNum_test'])) {
$pageNum_test = $_GET['pageNum_test'];
}
$startRow_test = $pageNum_test * $maxRows_test;

mysql_select_db($database_mySql, $mySql);
$query_test = "SELECT * FROM textform ORDER BY name ASC";
$query_limit_test = sprintf("%s LIMIT %d, %d", $query_test, $startRow_test, $maxRows_test);
$test = mysql_query($query_limit_test, $mySql) or die(mysql_error());
$row_test = mysql_fetch_assoc($test);

if (isset($_GET['totalRows_test'])) {
$totalRows_test = $_GET['totalRows_test'];
} else {
$all_test = mysql_query($query_test);
$totalRows_test = mysql_num_rows($all_test);
}
$totalPages_test = ceil($totalRows_test/$maxRows_test)-1;
?>
<?php

// if submitted form process and send mail
if ($REQUEST_METHOD == "POST") {

// just to be safe I strip out HTML tags
$name = strip_tags($name);
$email = strip_tags($email);
$address = strip_tags($address);
$age = strip_tags($age);

// set the variables
// replace $me@mysite.com with your email address
$sendto = "$******@hotmail.co.uk";
$subject = "does this work";
$message = "$name, $email\n$age\n\n$address";

// send the email
mail($sendto, $subject, $message);

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
// if submitted form display sent message
if ($REQUEST_METHOD=="POST") {
echo("<p><b>Thank you for your feedback. The following message was sent:</b></p>\n");
echo("<blockquote><pre>\n");
echo("$message");
echo("</pre></blockquote>");
}
// if not display form
else {
?>
<form method="post" name="form1" action="<?php echo("$script_name"); ?>">
<table>
<tr valign="baseline">
<td nowrap align="right">Name:</td>
<td><input type="text" name="name" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Email:</td>
<td><input type="text" name="email" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Address:</td>
<td><input type="text" name="address" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Age:</td>
<td><input name="age" type="text" value="" size="2" maxlength="2"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>

<?php } ?>

<?php do { ?>
<p>Name: <?php echo $row_test['name']; ?></p>
<p>Email: <?php echo $row_test['email']; ?></p>
<p>Address: <?php echo $row_test['address']; ?></p>
<p>age: <?php echo $row_test['age']; ?></p>
<?php } while ($row_test = mysql_fetch_assoc($test)); ?>

</body>
</html>
<?php
mysql_free_result($test);
?>


The submitted information gets logged in the database ok but I cannot get a copy of this info via email. :confused: Could someone please help?

Antivirus
07-19-2006, 06:16 PM
Two easiest methods i can think of would be either to create a datamanager for sending emails (read here (https://vborg.vbsupport.ru/showthread.php?t=119376)) or use the existing datamanager (read here (https://vborg.vbsupport.ru/showthread.php?t=82786)) for sending private messages to send you the info via PM, and have your account's UserCP>Options"Receive Email Notification of New Private Messages" turned on.