elmas156 Posted March 2, 2011 Share Posted March 2, 2011 Can anyone see why this might not be working? I've stared at it for so long, it looks like something from the matrix now! Here's the code: <?php if (isset($_POST['submit'])) { // If the form has been submitted. $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $position = $_POST['position']; $district = $_POST['district']; $message = $_POST['message']; $sendto = "[email protected]"; //this is actually supposed to go to my REAL email address... $emailsubject = "New Contact"; $emailmessage = "<html> <body> <table width='400' border='1' cellspacing='0' cellpadding='0'> <tr> <td width='150' align='left' valign='top'> Name: </td> <td width='250' align='right' valign='top'> $fname $lname </td> </tr> <tr> <td width='150' align='left' valign='top'> Email: </td> <td width='250' align='right' valign='top'> $email </td> </tr> <tr> <td width='150' align='left' valign='top'> Position/Title: </td> <td width='250' align='right' valign='top'> $position </td> </tr> <tr> <td width='150' align='left' valign='top'> District: </td> <td width='250' align='right' valign='top'> $district </td> </tr> <tr> <td width='150' align='left' valign='top'> Message: </td> <td width='250' align='right' valign='top'> </td> </tr> </table> <table width='400' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='400' align='left' valign='top'> $message </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 .= 'From: $fname $lname' . "\r\n"; // Tells the mail server who the email is from $fromaddress = '-f $email'; // Mail it mail($sendto, $emailsubject, $emailmessage, $headers, $fromaddress); } ?> Form variables are being passed fine, it's the actual mail() portion that is giving me problems. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/ Share on other sites More sharing options...
kenrbnsn Posted March 2, 2011 Share Posted March 2, 2011 The "From:" email header should contain an email address and you should be using double quotes, not single quotes when the strings contain variables. <?php $headers .= "From: $fname $lname <$email>\r\n"; $fromaddress = "-f $email"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1181957 Share on other sites More sharing options...
elmas156 Posted March 2, 2011 Author Share Posted March 2, 2011 OK, I've tried everything and I still can't get this to work... Here's my new code: <?php if (isset($_POST['submit'])) { // If the form has been submitted. $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $position = $_POST['position']; $district = $_POST['district']; $message = $_POST['message']; $sendto = "[email protected]"; $emailsubject = "New Contact"; $emailmessage = "<html> <body> <table width='400' border='1' cellspacing='0' cellpadding='0'> <tr> <td width='150' align='left' valign='top'> Name: </td> <td width='250' align='right' valign='top'> $fname $lname </td> </tr> <tr> <td width='150' align='left' valign='top'> Email: </td> <td width='250' align='right' valign='top'> $email </td> </tr> <tr> <td width='150' align='left' valign='top'> Position/Title: </td> <td width='250' align='right' valign='top'> $position </td> </tr> <tr> <td width='150' align='left' valign='top'> District: </td> <td width='250' align='right' valign='top'> $district </td> </tr> <tr> <td width='150' align='left' valign='top'> Message: </td> <td width='250' align='right' valign='top'> </td> </tr> </table> <table width='400' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='400' align='left' valign='top'> $message </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 .= "From: $fname $lname <$email>\r\n"; // Tells the mail server who the email is from $fromaddress = "-f $email"; // Mail it mail($sendto, $emailsubject, $emailmessage, $headers, $fromaddress); } ?> I even tried removing this line: $fromaddress = "-f $email"; I know that the mail() function is enabled on my server because I've used it with other pages, it just won't work here for some reason. Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182023 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2011 Share Posted March 2, 2011 The From: header should be set to a valid address on your server. The fifth '-f' parameter should also be set to a valid address on your server, and should have no space in it. Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182090 Share on other sites More sharing options...
kenrbnsn Posted March 2, 2011 Share Posted March 2, 2011 The From: header should be set to a valid address on your server. The fifth '-f' parameter should also be set to a valid address on your server, and should have no space in it. That's not necessarily true. On my server that's not the case. It really depends on the server's configuration. Ken Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182106 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2011 Share Posted March 2, 2011 That's what I've found with GoDaddy when problems like this crop up. Technically the From: header should be that way anyhow, from my understanding of things, and a Reply-to: header used if that functionality is desired. The fifth parameter isn't always needed, but if required and used, should not have a space in it. Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182112 Share on other sites More sharing options...
elmas156 Posted March 3, 2011 Author Share Posted March 3, 2011 So using the From: header, would I be able to use a variable ($email) so that it appears as though the email is coming from the user who filled out the form, or should I use a general or catch all email address on my server? Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182120 Share on other sites More sharing options...
Pikachu2000 Posted March 3, 2011 Share Posted March 3, 2011 The From: header gets set to a valid email address on your server, then you can add a Reply-to: header with the address supplied by the user who submitted the form. Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182124 Share on other sites More sharing options...
elmas156 Posted March 3, 2011 Author Share Posted March 3, 2011 Ah... so I should do this: $headers .= 'From: My Site <[email protected]>' . "\r\n"; $headers .= "Reply-to: $fname $lname <$email>" . "\r\n"; Look right to you? Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182127 Share on other sites More sharing options...
PFMaBiSmAd Posted March 3, 2011 Share Posted March 3, 2011 A) Not many sending mail servers will send an email when the From: address is not a valid mail address hosted at the sending mail server because it does not satisfy the relaying restrictions, assuming that the To: address is also not hosted at the sending mail server (sending it to yourself) as that would satisfy most relaying restrictions in itself. B) Not very many of the major ISP's receiving mail servers will accept an email where the domain in the From: address does not correspond to the sending mail server, either directly as best as can be determined by the dns zone records at the sending mail server or where there is an SPF dns zone record at the domain in the from address that says the sending mail server is authorized to send email for that domain. Are you even sure that the code where your mail() is at is being executed and are there any php errors, with error_reporting set to at lest E_ALL and display_errors set to ON, that would help determine if your sending mail server is even accepting the email to send it? Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182131 Share on other sites More sharing options...
elmas156 Posted March 3, 2011 Author Share Posted March 3, 2011 Yes, my code is being executed now. I went back to the basic script that I started with and I am tweaking each section of it to try to get it to do what I want. When I tweak a section and it stops working, I know that's what was causing my code to fail. It turns out that the From: header and the fifth parameter was causing the failure when I was trying to use $email within them. Now I'm just trying to get the emails to display the user's info as the reply to info. Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182140 Share on other sites More sharing options...
PFMaBiSmAd Posted March 3, 2011 Share Posted March 3, 2011 The 5th parameter is a command line argument that is passed to the mail server when mail() is calling the mail server's binary/executable. If you are actually using SMTP, it doesn't mean anything. If you were using php's error_reporting/display_errors settings, php would probably help you by displaying any errors that the mail() function gets back from your sending mail server. Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182156 Share on other sites More sharing options...
elmas156 Posted March 3, 2011 Author Share Posted March 3, 2011 Got it. Thanks for everyone's help. I have everything working smoothly now. I would mark this as solved now but I don't see a link for that anymore... wonder why it was removed??? Quote Link to comment https://forums.phpfreaks.com/topic/229401-mail-not-going-through/#findComment-1182176 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.