Fix: php mail() slow to sent on Ubuntu

php_script_function_codeI recently installed sendmail to set up e-mail on my server. It’s as easy as intalling that package via apt-get:

apt-get install sendmail

E-mail was installed correctly and working properly, because I tested it by creating a testmail.php file with these contents:

<?php
mail ('mail @example.com', "Test title", "Test mail from postfix via terminal on Ubuntu server with sendmail");
?>

Then, from the command line, I check if everything was working as I was expecting via this command:

php -f testmail.php

However, I took about half a minute (~30 seconds) for this little PHP script to finish, which was too long so something was going wrong.

Ultimately, I had to edit my host file, found at /etc/hosts. I had something like this: 127.0.0.1 localhost, where I needed the FQDN, such as this: localhost.example.com

After changing this value, my issue was fixed and sending e-mails did no longer take half a minute, but rather less than a second.

 

Author Bio

Thank you for your interest in my blog! On this miniblog, I write mostly short (technical) blog posts that might interest other people. Read more about me or feel free to contact me.

 

Leave a Reply

Your email address will not be published. Required fields are marked *