Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail() timeout

Tags:

php

email

First a few infos:

  • Debian Squeeze
  • PHP 5.3.3
  • PHP with mod_cgi
  • I absolutely HAVE to use mail() in this case. For all my other projects I already use SMTP mailing.

I have isolated the problem of a site timeout to the PHP mail() function. This is the only line of code in a test.php file on my server:

<?php mail('[email protected]', 'test', 'test');

Which seems to take endless and is then terminated by mod_cgi after 40 seconds. The command

php -r "mail('[email protected]', 'test', 'test');"

on the command line sends the email instantly.

Please tell me which log files you want to see, the Apache log is this:

[Thu Jan 17 12:17:00 2013] [warn] [client 178.15.148.43] mod_fcgid: read data timeout in 40 seconds
[Thu Jan 17 12:17:00 2013] [error] [client 178.15.148.43] Premature end of script headers: test.php

I think the problem is that I accidentally ran chmod -R 775 on the root directory a few days ago. I fixed all errors already, besides this one.

like image 535
Rudolf Avatar asked Jan 17 '13 11:01

Rudolf


2 Answers

Most likely you use 2 different php.ini versions. one for cli and one for cgi. Debian have this setup i believe.

  • /etc/php5/cgi/php.ini
  • /etc/php5/cli/php.ini

Make sure that your cli and cgi versions have the same email configuration and it will work.

The mail configuration key is: [mail function]

Another possibility is that your web user does't have access to execute sendmail.

Also check spool permissions (updated)

like image 190
Danilo Kobold Avatar answered Nov 14 '22 06:11

Danilo Kobold


Do not rely on mail() as it is unreliable and leads to issues just like these. I've used phpMailer for years quite happily.

If you persist on mail() then check your settings in php.ini (explained at http://www.quackit.com/php/tutorial/php_mail_configuration.cfm). Note that usually CLI has a different php.ini than FastCGI.

Some more common problems:

  • FastCGI doesn't have permissions to use sendmail

  • Memory limit with large attachments

like image 39
Mirko Adari Avatar answered Nov 14 '22 04:11

Mirko Adari