I have migrated a website from its host to my server Windows 2003 w/ IIS6; I have installed PHP 5.3.2 on the server. Whenever I go to fill this contact form on the bottom left www.hansonandhanson.com The form appears to go through, however no email is ever sent. I have enabled SMTP on my IIS server and allowed relaying of messages. Here is the PHP script <?PHP if (isset($_REQUEST['action']) && $_REQUEST['action']=='Send') { if (isset($_REQUEST['email'], $_REQUEST['name']) && $_REQUEST['email'] !="" && $_REQUEST['name'] !="" && $_REQUEST['name'] !="Enter name here" && $_REQUEST['email'] !="Enter email here" && $name !="Enter name here") { // mail the partners $content = " Name = $name\n\n Email = $email \n\n Phone = $phone \n\n Comments = $comments \n\n"; $subject = "Case Form Inquiry"; $to = "jhart@biziteks.com"; $msg = $content; $headers = "From: $email \nReply-To: $email"; mail("$to", "$subject", "$msg", "$headers"); // mail the sender $content = "Hello $name, \n\nThank you for your case inquiry. "; $content .="One of our associates will contact you shortly. Have an excellent day."; $subject = "Do I Have a Case?"; $to = $email; $msg = $content; $headers = "From: attorneys@hansonandhanson.com \nReply-To: attorneys@hansonandhanson.com"; mail("$to", "$subject", "$msg", "$headers"); // insert into mysql $message=1; } else { $message=2; } } ?> <html> <head> <title>Hanson and Hanson Case Inquiry</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <FORM METHOD="post" ACTION="<?PHP echo $phpself; ?>" ENCTYPE="multipart/form-data" name=contact> <body bgcolor="#FFFFFF" text="#000000"> <div align="center"><font size=2 face=arial> <?PHP switch ($message) { case 1: echo "<html><head><title>redirect</title>\n"; echo "<META http-equiv=refresh content=2;URL=http://www.hansonandhanson.com/index.html\n"; echo "<font color=99cc99>Your request has been submitted. Thank you for asking us to hear your case.<br> We will be contacting you shortly</font>"; echo "</head> <body bgcolor=#ffffff>\n"; echo "</body></html> \n"; break; case 2: echo "<html><head><title>Redirect</title>\n"; echo "<META http-equiv=refresh content=2;URL=http://www.hansonandhanson.com/index.html\n"; echo "<font color=333366>Sorry, you must enter at least your first name, last name, and email address to submit a request. Please try again..</font>"; echo "</head> <body bgcolor=#ffffff>\n"; echo "</body></html> \n"; break; } ?> </font> <br> </div> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td> <?PHP if ($message !=1){ ?> <?PHP } ?> </td> </tr> </table> </form> </body> </html>
Have you ensured the following values are set? (Check with phpinfo()) SMTP string Used under Windows only: host name or IP address of the SMTP server PHP should use for mail sent with the mail() function. smtp_port int Used under Windows only: Number of the port to connect to the server specified with the SMTP setting when sending mail with mail(); defaults to 25. Only available since PHP 4.3.0. Also, put the following at the start of your file so that you see when the mail() function fails. error_reporting(E_ALL ^ E_NOTICE); ini_set('display_errors','1'); PHP:
SMTP = localhost smtp_port = 25 sendmail_from = jhart@biziteks.com sendmail_path = Warning: mail() [function.mail]: SMTP Server response: 503 5.5.2 Need Rcpt command. In CL\Webdata\www.hansonandhanson.com\phptest\contact-request.php on line 27
It looks like the option register_globals is disabled. You'll want to change every reference of $name, $email, $phone and $comments, to use $_REQUEST['fieldname'] instead, as you have in your if statement. You should also use CRLF (\r\n) instead of just LF (\n) when separating mail header lines. For example: // mail the partners $content = " Name = {$_REQUEST['name']}\n\n Email = {$_REQUEST['email']} \n\n Phone = {$_REQUEST['phone']} \n\n Comments = {$_REQUEST['comments']} \n\n"; $subject = "Case Form Inquiry"; $to = "jhart@biziteks.com"; $msg = $content; $headers = "From: {$_REQUEST['email']}\r\nReply-To: {$_REQUEST['email']}"; mail("$to", "$subject", "$msg", "$headers"); PHP: You'll want to apply the same changes I made to the code to e-mail the sender as well.
So liek this? <?PHP error_reporting(E_ALL ^ E_NOTICE);ini_set('display_errors','1'); if (isset($_REQUEST['action']) && $_REQUEST['action']=='Send') { if (isset($_REQUEST['email'], $_REQUEST['name']) && $_REQUEST['email'] !="" && $_REQUEST['name'] !="" && $_REQUEST['name'] !="Enter name here" && $_REQUEST['email'] !="Enter email here" && $_REQUEST['name'] !="Enter name here") { // mail the partners $_REQUEST['content'] = " Name = $_REQUEST['name']\n\n Email = $_REQUEST['email'] \n\n Phone = $_REQUEST['phone'] \n\n Comments = $comments \n\n"; $_REQUEST['subject'] = "Case Form Inquiry"; $_REQUEST['to'] = "jhart@biziteks.com"; $_REQUEST['msg'] = $_REQUEST['content']; $_REQUEST['headers'] = "From: $_REQUEST['email'] \r\nReply-To: $_REQUEST['email']"; mail("$_REQUEST['to']", "$_REQUEST['subject']", "$_REQUEST['msg']", "$_REQUEST['headers']"); // mail the sender $_REQUEST['content'] = "Hello $_REQUEST['name'], \n\nThank you for your case inquiry. "; $_REQUEST['content'] .="One of our associates will contact you shortly. Have an excellent day."; $_REQUEST['subject'] = "Do I Have a Case?"; $_REQUEST['to'] = $_REQUEST['email']; $_REQUEST['msg'] = $_REQUEST['content']; $_REQUEST['headers'] = "From: attorneys@hansonandhanson.com \nReply-To: attorneys@hansonandhanson.com"; mail("$_REQUEST['to']", "$_REQUEST['subject']", "$_REQUEST['msg']", "$_REQUEST['headers']"); // insert into mysql $message=1; } else { $message=2; } } Do I need to change the $message= ones as well?
Not quite, you don't set the $_REQUEST values, just retrieve them, e.g. $msg = $_REQUEST['content']; PHP: Also, you can't reference arrays in strings that way, so you'd either have to store them in a variable first or use $_REQUEST['headers'] = "From: {$_REQUEST['email']} \r\nReply-To: {$_REQUEST['email']}"; PHP:
<?PHP if (isset($_REQUEST['action']) && $_REQUEST['action']=='Send') { if (isset($_REQUEST['email'], $_REQUEST['name']) && $_REQUEST['email'] !="" && $_REQUEST['name'] !="" && $_REQUEST['name'] !="Enter name here" && $_REQUEST['email'] !="Enter email here" && $_REQUEST['name'] !="Enter name here") { // mail the partners $content = " Name = $_REQUEST['name'] \n\n Email = $_REQUEST['email'] \n\n Phone = $_REQUEST['phone'] \n\n Comments = $_REQUEST['comments'] \n\n"; $subject = "Case Form Inquiry"; $to = "jhart@biziteks.com"; $msg = $_REQUEST['content']; $headers = "From: $_REQUEST['email] \nReply-To: $_REQUEST['email'] "; mail("$to", "$subject", "$msg", "$headers"); // mail the sender $content = "Hello $_REQUEST['name'] , \n\nThank you for your case inquiry. "; $content .="One of our associates will contact you shortly. Have an excellent day."; $subject = "Do I Have a Case?"; $to = $_REQUEST['email'] ; $msg = $_REQUEST['content']; $headers = "From: \nReply-To: "; mail("$to", "$subject", "$msg", "$headers"); // insert into mysql $message=1; } else { $message=2; } } ?>
<?PHP if (isset($_REQUEST['action']) && $_REQUEST['action']=='Send') { if (isset($_REQUEST['email'], $_REQUEST['name']) && $_REQUEST['email'] !="" && $_REQUEST['name'] !="" && $_REQUEST['name'] !="Enter name here" && $_REQUEST['email'] !="Enter email here" && $_REQUEST['name'] !="Enter name here") { // mail the partners $content = " Name = {$_REQUEST['name']} \n\n Email = {$_REQUEST['email']} \n\n Phone = {$_REQUEST['phone']} \n\n Comments = {$_REQUEST['comments']} \n\n"; $subject = "Case Form Inquiry"; $to = "jhart@biziteks.com"; $msg = $_REQUEST['content']; $headers = "From: {$_REQUEST['email']} \nReply-To: {$_REQUEST['email']} "; mail("$to", "$subject", "$msg", "$headers"); // mail the sender $content = "Hello {$_REQUEST['name']} , \n\nThank you for your case inquiry. "; $content .="One of our associates will contact you shortly. Have an excellent day."; $subject = "Do I Have a Case?"; $to = $_REQUEST['email'] ; $msg = $_REQUEST['content']; $headers = "From: attorneys@hansonandhanson.com \nReply-To: attorneys@hansonandhanson.com"; mail("$to", "$subject", "$msg", "$headers"); // insert into mysql $message=1; } else { $message=2; } } ?> PHP:
Thanks Void, That is now succesfully sending the emails out, however there is no content int he body of the message, Any clues?
You're putting the message content into $content; $content = "Hello {$_REQUEST['name']} , \n\nThank you for your case inquiry. "; $content .="One of our associates will contact you shortly. Have an excellent day."; PHP: but then you set $msg to $_REQUEST['content'] which doesn't exist $msg = $_REQUEST['content']; PHP: Finally, when you sent the message, you're using $msg as the body: mail("$to", "$subject", "$msg", "$headers"); PHP: Delete both the $msg = $REQUEST... lines and change your mail() call to: mail("$to", "$subject", "$content", "$headers"); PHP: That should sort it for you.