php mail() function painfully slow on local development machine

Posted by Michael B on Server Fault See other posts from Server Fault or by Michael B
Published on 2010-08-24T03:15:38Z Indexed on 2011/01/13 5:55 UTC
Read the original article Hit count: 167

Filed under:
|
|
|

Background: If you have set up a local apache server for development purposes you may have run into the problem where sendmail takes a long time (at least one minute) to send emails. This is extremely frustrating if you are trying to debug a problem with an email you have generated.

There are several forum posts on the internet that discuss this problem. However, none of theme described what to do in enough detail for my limited knowledge. Here are the steps that worked for me:

1) find your hostname (in case you've forgotten it) using this command:

:~$ cat /hosts/hostname

myhostname

2) edit the file /etc/hosts and make sure the first line is the following:

127.0.0.1 localhost.localdomain localhost myhostname

3) edit the sendmail configuration file ( /etc/mail/sendmail.cf in Ubuntu) and Uncomment the line #O HostsFile=/etc/hosts

4) Restart the computer. The computer should boot up much faster now and the mail() function should return almost immediately. HOWEVER, the emails won't actually be sent unless you follow step 5.

5) You must new use the sendmail '-f' option whenever using the mail function. For example:

mail('[email protected]', 'the subject', 'the message', null, '[email protected]');

My question for my fellow serverfaulters is:

What further changes can be made so that I don't have to use the sendmail -f option? Although it's not very hard to add the -f option, it is a problem when your CMS (such as Drupal) does not use the -f option when sending mail. You would need to hack a core module to add this option.

© Server Fault or respective owner

Related posts about php

Related posts about sendmail