Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seeking error reporting for failed mail() 2

Status
Not open for further replies.

spamjim

Instructor
Mar 17, 2008
1,368
US
Our web server was recently relocated and we are having DNS issues with some setting that apparently did not transfer well. We have a mail function that seems to successfully send to anyone but our own domain. Mail sent to anyone@gmail.com or anyone@yahoo.com works but mail sent to anyone@ourowndomain.com fails at the mail() function.

Unfortunately, I cannot get PHP to report why mail() is failing. I'm hoping that by finding a verbose error with the mail function, I can start to diagnose what has gone wrong with our DNS modifications.

Here are snippets from the function. I have turned on all reporting that I know to turn on. The mail function is set to give a success message when it works, or a warning when it fails. Can anyone offer ideas on how to get it to specify why it fails?

Code:
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
ini_set('error_reporting', E_ALL); 
error_reporting(E_ALL);

//...

if (@mail($to, $subject, $body, $headers, "-f $from")) {
    $alertmessage .= "<font color=\"green\"><b>Mail has been sent to $to</b></font><br /><br />"; 
    } else {
    $alertmessage .= "<font color=\"red\"><b>Mail has NOT been sent to $to</b></font><br /><br />";
    }
 
First, you can get a lot more info and a lot more options if you use the PHPMailer. Just search the net for it. Second, you may switch on "populate last error" in php.ini and check it. I hope it contains the error, even though you suppress it with the "@" symbol.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
mail() is not failing. you know that it does work in certain circumstances. therefore it works.

if mail is not being delivered to particular places this is outside the scope of mail(). Instead you need to look at your smtp routing settings inside your smtp server. also check your mta settings. both outside the scope of this forum.

to debug the current failures look at the badmail and delivery logs of your mta.

also, i tend not to use the params setting of the mail command. instead append a header to the $headers parameter. the fourth argument of the mail command is mta specific, whereas headers tend to me more generic.

Code:
$headers .= "From: $from \r\n";

this is unlikely to be related to your issue however.
 
A belated thanks for the tips...

The problem turned out to be the same as that discussed here:

mail() was defaulting to use the localhost mail server before attempting a lookup for our desired external mail server. As much as I tried to use explicit SMTP settings with phpmailer instead of plain ol' mail(), it still failed because PHP only wanted to look at the localhost where we had no mail accounts set up.

In case anyone stumbles onto this thread with a similar issue, I found the solution to be simply turning off all mail services in the IIS/Plesk interface that managed localhost mail. That eliminated the localhost distraction and let PHP point to the correct external mail server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top