Hi All, I have this PHP code that Inserts a record to mysql database. I was wondering if someone could help me to modify this code to send email upon submitting the record. send email and the user. here is the php code: /////////////////////////////// <?php require_once('Connections/psyc.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $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"] == "form2")) { $insertSQL = sprintf("INSERT INTO helpu (ID, date_created, sunetid, first_name, last_name, email, phone, Reported_issue) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['ID'], "int"), GetSQLValueString($_POST['date_created'], "date"), GetSQLValueString($_POST['sunetid'], "text"), GetSQLValueString($_POST['first_name'], "text"), GetSQLValueString($_POST['last_name'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['phone'], "text"), GetSQLValueString($_POST['Reported_issue'], "text")); mysql_select_db($database_psyc, $psyc); $Result1 = mysql_query($insertSQL, $psyc) or die(mysql_error()); } ?> <style type="text/css"> .headin_1 { text-align: center; } .Tables { } </style> <div> <p>Helpu</p> <p> </p> <form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">ID:</td> <td><input type="text" name="ID" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Date_created:</td> <td><input type="text" name="date_created" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Sunetid:</td> <td><input type="text" name="sunetid" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">First_name:</td> <td><input type="text" name="first_name" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Last_name:</td> <td><input type="text" name="last_name" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Email:</td> <td><input type="text" name="email" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Phone:</td> <td><input type="text" name="phone" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Reported_issue:</td> <td><input type="text" name="Reported_issue" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Insert record" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form2" /> </form> <p> </p> </div> <p> </p> //////////////////////////////// I have also attached the index.php file in here. Thanks for any help, Abby
The web-server will be running on MAC OSX 10.7 lion server , so whichever is easier and more compatible to setup. On the Server I have already enabled the PHP and Email. So probably PHP would the one we need to use?? Thanks in advance, Abby
After this line $Result1 = mysql_query($insertSQL, $psyc) or die(mysql_error()); PHP: Add this mail('email@address.com', 'Subject', 'Message', "From: Notification <notification@website.com>\r\n"); PHP: The from field can be changed to show any email you want, but could end up being caught by a spam filter. Alternatively, you can use HTML code in the email, by adding Content-Type to the 4th argument (the email headers) mail('email@address.com', 'Subject', '<p>HTML message - <a href="#">Link</a></p>', "From: Notification <notification@website.com>\r\nContent-Type: text/html\r\n"); PHP: Keep in mind PHP there must be an SMTP server configured to work with PHP, as it may fail. Not sure if OS X has a native SMTP handler.
Adding this line: mail('email@address.com', 'Subject', '<p>HTML message - <a href="#">Link</a></p>', "From: Notification <notification@website.com>\r\nContent-Type: text/html\r\n"); Works very well!!! thank you!! Now, if I want to add some of the fields into the email content how should I do it. Fields name: first_name Last_name Phone email Reported_issue Thanks in advance,
Using : .PHP_EOL Did what I wanted!!! here is part of code: $to = "x@yahoo.com"; $subject = "Helpu Notification System."; $message = "First_name: ".$_POST['first_name'].PHP_EOL . "Last_name: " .$_POST['last_name'].PHP_EOL. "Email: " .$_POST['email'].PHP_EOL. "Reported_Issues: ". $_POST['Reported_issue'].PHP_EOL. "Phone_Number: " . $_POST['phone']; $headers = "From: Helpu System\r\n" . $from = "Helpu System"; $headers = "From:" . $_POST['first_name'] ; $body = mail($to,$subject,$message , $body, $headers );