PHP mail()函数没有返回true或false - 脚本只是超时

The php mail function has stopped working on a Centos 5.7 server. The scripts containing the function call were working on this server until the last couple of days but there have not been any configuration changes..

Whenever I call the mail() function the PHP script just stalls/freezes on that line until it reaches the script timeout limit.

$msgheader  = 'MIME-Version: 1.0' . "
";
$msgheader .= 'Content-type: text/html; charset=iso-8859-1' . "
";
$msgheader .= "From: Test Name <no-reply@servername.com>
";

echo "About to send mail ->";
mail ("test@servername.com", "Test Subject", "Test Body", $msg_header);
echo "Script never reaches this line!";

I have modified the email addresses for this question, but I know they are not the issue as the script executed correctly previously.

I have tried changing the email address to various personal accounts (e.g. @yahoo.com) and it still doesn't work, so I don't think this is due to spam filtering at the organization where my users reside.

What could be causing the mail function to get stuck until the script timeout rather than just immediately return false if it can't send the email? What settings can I look at?

Thanks!

EDIT:

  • There are no errors in the Apache error logs
  • php.ini has:

    SMTP = localhost; smtp_port = 25; sendmail_path = /usr/sbin/sendmail -t -i

This issue was related to a problem with the DNS settings of the server.

After attempting:

yum update

it became clear the server was having an issue connecting to the internet. This explains the long timeouts attempting to make the outbound connection to send the email.

I had to add

search localdomain

to my /etc/resolv.conf file in CentOS to establish the outbound connection. This question was better posted on ServerFault now that I know that issue.