lukeawade Posted February 3, 2009 Share Posted February 3, 2009 I have a registration page that inserts information to my database and I'm trying to send an email with some additional information to the person who registered but I cant figure it out. Here is what I have. Not sure where to add the email code. <?php require_once('Connections/connRegistration.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; } } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO dashboard_registration (reg_id, proj_id, first_name, last_name, company, address1, address2, city, `state`, zip, phone, cell_phone, fax, email, discipline, registration_date, ip, distribution_method) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['reg_id'], "int"), GetSQLValueString($_POST['proj_id'], "int"), GetSQLValueString($_POST['first_name'], "text"), GetSQLValueString($_POST['last_name'], "text"), GetSQLValueString($_POST['company'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['city'], "text"), GetSQLValueString($_POST['state'], "text"), GetSQLValueString($_POST['zip'], "int"), GetSQLValueString($_POST['phone'], "text"), GetSQLValueString($_POST['cell_phone'], "text"), GetSQLValueString($_POST['fax'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['discipline'], "text"), GetSQLValueString($_POST['registration_date'], "date"), GetSQLValueString($_POST['ip'], "text"), GetSQLValueString($_POST['distribution_method'], "text")); mysql_select_db($database_connRegistration, $connRegistration); $Result1 = mysql_query($insertSQL, $connRegistration) or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted February 3, 2009 Share Posted February 3, 2009 At the end of the IF? Quote Link to comment Share on other sites More sharing options...
lukeawade Posted February 3, 2009 Author Share Posted February 3, 2009 I tried that but maybe I'm not putting in the right information. <?php // Your email address $email = GetSQLValueString($_POST['email'], "text"); // The subject $subject = "Enter your subject here"; // The message $message = "Enter your message here"; mail($email, $subject, $message, "From: admin@test.com");?> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted February 3, 2009 Share Posted February 3, 2009 Try using a real from address Quote Link to comment Share on other sites More sharing options...
lukeawade Posted February 3, 2009 Author Share Posted February 3, 2009 I did. I just changed it to put it on here. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted February 3, 2009 Share Posted February 3, 2009 Ok have a look at the php manual about headers, and also try removing the function on the email address (to). Quote Link to comment Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 What type of email address are you sending it? If it is Yahoo, AOL, or Hotmail, they tend to not accept emails from a lot of php scripts without valid headers, or where servers who do not ping back that they have a mail server on them... Quote Link to comment Share on other sites More sharing options...
lukeawade Posted February 3, 2009 Author Share Posted February 3, 2009 I'm sending from a godaddy email account. admin@m-repro.com. Quote Link to comment Share on other sites More sharing options...
lukeawade Posted February 4, 2009 Author Share Posted February 4, 2009 Any help with this is appreciated. I am using the code below and it isnt sending an email. <?php require_once('Connections/connRegistration.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; } } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO dashboard_registration (reg_id, proj_id, first_name, last_name, company, address1, address2, city, `state`, zip, phone, cell_phone, fax, email, discipline, registration_date, ip, distribution_method) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['reg_id'], "int"), GetSQLValueString($_POST['proj_id'], "int"), GetSQLValueString($_POST['first_name'], "text"), GetSQLValueString($_POST['last_name'], "text"), GetSQLValueString($_POST['company'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['city'], "text"), GetSQLValueString($_POST['state'], "text"), GetSQLValueString($_POST['zip'], "int"), GetSQLValueString($_POST['phone'], "text"), GetSQLValueString($_POST['cell_phone'], "text"), GetSQLValueString($_POST['fax'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['discipline'], "text"), GetSQLValueString($_POST['registration_date'], "date"), GetSQLValueString($_POST['ip'], "text"), GetSQLValueString($_POST['distribution_method'], "text")); $email = $_POST['email']; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: admin@m-repro.com' "\r\n"; mail ("$email", 'Statement for', "Thank You!", $headers); mysql_select_db($database_connRegistration, $connRegistration); $Result1 = mysql_query($insertSQL, $connRegistration) or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted February 5, 2009 Share Posted February 5, 2009 change mail ("$email", 'Statement for', "Thank You!", $headers); to if( mail ("$email", 'Statement for', "Thank You!", $headers)) echo "Sent"; else echo "failed"; Quote Link to comment Share on other sites More sharing options...
lukeawade Posted February 5, 2009 Author Share Posted February 5, 2009 I figured out this works. <?php $email = $_POST['email']; $fname = $_POST['first_name']; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: admin@m-repro.com' . "\r\n"; mail("$email",'MySmartPlans Registration', "$fname, \n\nThank you for registering.", $headers);?> But the problem is sometimes I get like 5 or 6 of the same email in a row and the \n\n doesnt send the Thank You to another line. How do I make the HTML work? Quote Link to comment Share on other sites More sharing options...
lukeawade Posted February 5, 2009 Author Share Posted February 5, 2009 I figured out why I am getting the same email a bunch of times. Its putting in my database more than once. Why is it doing that? Here is what I have? Also still need to know how to make HTML work like \n. <?php if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO dashboard_registration (reg_id, proj_id, first_name, last_name, company, address1, address2, city, `state`, zip, phone, cell_phone, fax, email, discipline, registration_date, ip, distribution_method) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['reg_id'], "int"), GetSQLValueString($_POST['proj_id'], "int"), GetSQLValueString($_POST['first_name'], "text"), GetSQLValueString($_POST['last_name'], "text"), GetSQLValueString($_POST['company'], "text"), GetSQLValueString($_POST['address1'], "text"), GetSQLValueString($_POST['address2'], "text"), GetSQLValueString($_POST['city'], "text"), GetSQLValueString($_POST['state'], "text"), GetSQLValueString($_POST['zip'], "int"), GetSQLValueString($_POST['phone'], "text"), GetSQLValueString($_POST['cell_phone'], "text"), GetSQLValueString($_POST['fax'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['discipline'], "text"), GetSQLValueString($_POST['registration_date'], "date"), GetSQLValueString($_POST['ip'], "text"), GetSQLValueString($_POST['distribution_method'], "text")); $email = $_POST['email']; $fname = $_POST['first_name']; $serial = $_POST['cell_phone']; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: MySmartPlans Registration <admin@m-repro.com>' . "\r\n"; mail("$email",'MySmartPlans Registration', "$fname, \nThank you for registering for MySmartPlans. Put in your Serial Number below to your MySmartPlans. \nSerial Number: $serial \nIf you have any issues please call 816-221-7881.", $headers); mysql_select_db($database_connRegistration, $connRegistration); $Result1 = mysql_query($insertSQL, $connRegistration) or die(mysql_error()); }?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.