matt142857 Posted November 15, 2011 Share Posted November 15, 2011 Hi, I am having a problem with my Website mail. Basically the mail was working fine yesterday but last night I edited the PHP script slightly because for some reason the page that it was directed to had gone missing and was turning up an 404 error, which was just a newsuince as the email was still sent. So I just edited it so that it echo'ed a message saying thanks. but is seems today the mail is not getting to its destination. The PHP returns no errors and returns the success message fine but after saying its been sent it never appears. I have tried different email addresses on different servers and that was no use and I have also changed the code back to how it was yesterday. and it still doesn't work. I have also put the page up on one of my other sites which I know everything is set up properly and it works fine, making me think that it is a mail setup issue. but as I did not set up the mail at all and quite frankly don't really understand it, I don't know how it is meant to be set up as I just use google apps for sites that I set up. So yeah I am trying to work out what could have gone wrong since yesterday but I don't really understand it, below is the code as it as now and as it was yesterday: <?php $EmailFrom = "[email protected]"; $EmailTo = "[email protected]"; $Subject = "Website enquiry"; $Name = Trim(stripslashes($_POST['Name'])); $Tel = Trim(stripslashes($_POST['Tel'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Tel: "; $Body .= $Tel; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> and the page is at www.sullyco.co.uk/contactengine.php as you can see the page is redirecting to a page that does not exist(contactthanks.php) indicating that the message was sent successfully. it is also the part I edited as a quick fix last night I just got it to echo a success message. Thanks for any help on this, I have been trying to work it out all morning, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/ Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 Did your code ever have headers that it passed to the mail() construct? While it is possible for PHP to send an email without additional/custom headers, the default headers are not suited for most mail servers. If you're on a linux server, you might be able to find mail that didn't get sent in a default or catch all account, depends ... Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288375 Share on other sites More sharing options...
matt142857 Posted November 15, 2011 Author Share Posted November 15, 2011 It did have these basic headers: $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); Should I add more? Cheers, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288402 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 It did have these basic headers: $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); Should I add more? Cheers, Matt Those headers should work, there did appear to be present in the code snippet you pasted up top. Make sure '$headers' is the last param in the mail() construct. Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288442 Share on other sites More sharing options...
matt142857 Posted November 15, 2011 Author Share Posted November 15, 2011 Yeah its not in te code above but i did try that and is now in the code and reads as follows: // send email $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $success = mail($EmailTo, $Subject, $Body, $headers); But unfortunately it makes no difference. Thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288454 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 have you tried to return the value of mail()? like var_dump($success)? Or, try var_dump(error_get_last()), right after mail() Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288463 Share on other sites More sharing options...
matt142857 Posted November 15, 2011 Author Share Posted November 15, 2011 That come up with this, which I am not totaly sure what it means: array(4) { ["type"]=> int( ["message"]=> string(21) "Undefined index: Tel" ["file"]=> string(68) "/filer/1/en-www/109ALL767V4YN5CY/www.sullyco.co.uk/contactengine.php" ["line"]=> int(7) } Which I have left the code online if you go to http://www.sullyco.co.uk/contact.php and put some blurb in the text boxes(there is no email validation or anything at the moment. Thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288471 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 Okay, lets try this; create a new file and put the following code in it. Change the names and addresses as appropriate so that it uses real email addresses and names. Then run it in a browser. If this isn't working then there may be an issue with the server's SMTP settings. <?php $to = '[email protected]'; $toName = 'Test'; $from = '[email protected]'; $fromName = 'Me'; $subject = 'Test Subject'; $message = '<b>This is a test message.</b>'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'To: ' . $toName . ' <' . $to . '>' . "\r\n"; $headers .= 'From: ' . $fromName . ' <' . $from . '>' . "\r\n"; mail($to, $subject, $message, $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288483 Share on other sites More sharing options...
matt142857 Posted November 15, 2011 Author Share Posted November 15, 2011 I have just done that and unfortunately it also did not work, but again it worked fine on a test site, which as you say indicates a problem with the SMTP settings, unfortunately though I know very little about SMTP or mail settings of any sort. Thanks again, I really appreciate the help you are giving, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288492 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 Is this a linux or windows server (the one that it is not working on)? Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288495 Share on other sites More sharing options...
matt142857 Posted November 15, 2011 Author Share Posted November 15, 2011 I believe it is Linux, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288504 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 I believe it is Linux, Matt Do you control the server or is it a hosted solution? Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288505 Share on other sites More sharing options...
matt142857 Posted November 15, 2011 Author Share Posted November 15, 2011 I do not know, I did not set it up, I just took it over. I know that the site is hosted by eclipse.net.uk which on there it says 'Email for sullyco.co.uk is configured for SMTP' Apart from that I have no Idea, sorry, how do I find out? Thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288506 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 I do not know, I did not set it up, I just took it over. I know that the site is hosted by eclipse.net.uk which on there it says 'Email for sullyco.co.uk is configured for SMTP' Apart from that I have no Idea, sorry, how do I find out? Thanks, Matt Well, if you have a support contact, I would start there, and ask them for support. If you have shell access you could check the log dump on the server and see if anything is there. You could also try to find another mail server that you could make SMTP connections to. Bottom line, without a valid MTA (Mail Transport Authority), PHP is not going to be able to transfer mail. Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288511 Share on other sites More sharing options...
matt142857 Posted November 15, 2011 Author Share Posted November 15, 2011 Just to clarify, I am not the owner of the site or business I just re built and designed it not touching the original setup. Looking around the eclipse acount I cound this: Email for domain sullyco.co.uk is configured for SMTP The access account that your mail server is connected to is [email protected] The IP address that your mail server is running on is 82.152.45.250 If you wish to change these details, please click on the Modify button. WARNING: If you are using your own mail server you will need to ensure that it is not misconfigured and operating as an open relay. If an open relay is running on your server then our mail servers may reject email from your server. Suggesting that the company controls the server? EDIT: in response to your next reply: To be honest I am a little confused about what you just said there, sorry. As it is a running business I am worried to go in and mess up there email system preventing any emails from being sent. Thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288513 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 Right, so basically, they have their mail server running in the same network/LAN as this web server, right? Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288518 Share on other sites More sharing options...
matt142857 Posted November 15, 2011 Author Share Posted November 15, 2011 I don't know, it looks like it, I might be able to find out more from the owner of the company tomorrow, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288523 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 Okay, well that's what it appears to be. So, basically, the most likely issue (especially if it's Exchange), is that the mail server is not allowing the web server as an authorized relay. The mail server admin needs to make the IP of this web server, an authorized relay server. He/She will not want to make it an 'open' relay and will want to require auth from the web server. Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288526 Share on other sites More sharing options...
matt142857 Posted November 15, 2011 Author Share Posted November 15, 2011 OK so I should contact Eclipse and ask that they authorise the IP of the site then? Thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288527 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 OK so I should contact Eclipse and ask that they authorise the IP of the site then? Thanks, Matt Yeah, whomever controls the mail server, needs to allow the IP addess of the web server as an authorized relay or sender. Now, most likely, they won't allow the web server to be an open relay. So they'll probably require the web server to authenticate before sending email. If you get to that point; then in PHP, you should be able to make SMTP connections to the mail server, using the username and password they provide you. They may also give you a non-standard port to connect to, so be on the look out for that as well. Feel free to PM or email me if you need further assistance, once you get to that point. Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288530 Share on other sites More sharing options...
matt142857 Posted November 16, 2011 Author Share Posted November 16, 2011 Thankyou very much for all the help, I shall let you know how I get on. Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288535 Share on other sites More sharing options...
matt142857 Posted November 16, 2011 Author Share Posted November 16, 2011 Thanks again for the help, after sending a support ticket to Eclipse, before I have a reply it miraculously works again! I have also edited what I originally wanted and it still works fine, so I don't know if they did something before replying or what, but it works now so that's great. Cheers, Matt Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288722 Share on other sites More sharing options...
phporcaffeine Posted November 16, 2011 Share Posted November 16, 2011 Thanks again for the help, after sending a support ticket to Eclipse, before I have a reply it miraculously works again! I have also edited what I originally wanted and it still works fine, so I don't know if they did something before replying or what, but it works now so that's great. Cheers, Matt That's how it usually happens, you send a ticket, they fix it and usually don't respond. Congrats. Quote Link to comment https://forums.phpfreaks.com/topic/251183-problem-with-mail-not-getting-past-my-server/#findComment-1288724 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.