rich_traff Posted January 19, 2012 Share Posted January 19, 2012 Hi, i've written a script that use's mail() in it to send some information. I've tested this on my own server and it works fine, however when i put it onto a clients server the email does not come through. Here is the email part of the script <?php $to = "me@example.com"; $subject = "subject"; $body = "Body of email"; $email_from = "Example"; ini_set("sendmail_from", $email_from); $headers = "From: $email_from"; if (mail($to, $subject, $body, $headers)) { echo("<p>Your email has been sent</p>"); } else { echo("<p>An error has occured</p>"); } So on my own server, the script runs, the message "Your email has been sent" shows and i receive the email. On my clients server, the script runs, the message "Your email has been sent" still shows, i do not get an error message, but the email never gets received. So im assuming it must be a config issue with their server… A problem though is that i only have ftp details for it and currently no way of contacting the web host, i don't even know where its hosted, all i have is a host ip, username and password. So, i am looking for some advice on A) what i should be looking for to figure out why the email is not getting through B) how to go about finding that info? C) options for improving the script that will ensure the email is sent/received.. Can anyone offer any advice? Quote Link to comment https://forums.phpfreaks.com/topic/255385-mail-not-working-options-for-finding-out-why/ Share on other sites More sharing options...
raknjak Posted January 19, 2012 Share Posted January 19, 2012 Are there no files called error_log in your webserver webroot for example? Maybe something like this in your code will work, depending on what the server allows. ini_set('error_reporting', E_ALL); Since mail() relays it's requests through sendmail check those logs, too - no way for you to access those though /var/log/mail.log. You could see whether an e-mail is actually sent with this kind of script: http://www.howtoforge.com/how-to-log-emails-sent-with-phps-mail-function-to-detect-form-spam let us know how it turns out Quote Link to comment https://forums.phpfreaks.com/topic/255385-mail-not-working-options-for-finding-out-why/#findComment-1309423 Share on other sites More sharing options...
rich_traff Posted January 20, 2012 Author Share Posted January 20, 2012 I tried setting error reporting by placing it in with the mail part of the script <?php $email_from = "Example"; ini_set("sendmail_from", $email_from); ini_set('error_reporting', E_ALL); $headers = "From: $email_from"; No errors showed though, would it make a difference where i placed it? Also i looked in the error_log file from the site root but found nothing there. the last entry was from a few days ago and detailed some missing css files, there's nothing recent that suggests anything to do with mail or the script i have written. Am still to try the mail log script you suggested Quote Link to comment https://forums.phpfreaks.com/topic/255385-mail-not-working-options-for-finding-out-why/#findComment-1309673 Share on other sites More sharing options...
AyKay47 Posted January 20, 2012 Share Posted January 20, 2012 I tried setting error reporting by placing it in with the mail part of the script <?php $email_from = "Example"; ini_set("sendmail_from", $email_from); ini_set('error_reporting', E_ALL); $headers = "From: $email_from"; No errors showed though, would it make a difference where i placed it? Also i looked in the error_log file from the site root but found nothing there. the last entry was from a few days ago and detailed some missing css files, there's nothing recent that suggests anything to do with mail or the script i have written. Am still to try the mail log script you suggested what are the SMTP settings in the php.ini file of the clients server? also, as the manual states. Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise. It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination. Quote Link to comment https://forums.phpfreaks.com/topic/255385-mail-not-working-options-for-finding-out-why/#findComment-1309676 Share on other sites More sharing options...
rich_traff Posted January 20, 2012 Author Share Posted January 20, 2012 what are the SMTP settings in the php.ini file of the clients server? i dont have access to the php.ini file and currently am unable to contact the host admin. phpinfo() gives the following; SMTP - localhost - localhost smtp_port - 25 - 25 if that helps? Quote Link to comment https://forums.phpfreaks.com/topic/255385-mail-not-working-options-for-finding-out-why/#findComment-1309677 Share on other sites More sharing options...
Pikachu2000 Posted January 21, 2012 Share Posted January 21, 2012 You're getting a TRUE returned from the mail() function, indicating the mail server accepted the email from php. Someone who is able to do so should check the mail server logs and see if there's any indication of what's going on. Quote Link to comment https://forums.phpfreaks.com/topic/255385-mail-not-working-options-for-finding-out-why/#findComment-1309741 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.