Solving slowness of php mail() function

If you suddenly noticed that mail() functions works very slowly and causes long page loads, here is quick solution.

By default php mail() functions works via SendMail service which requires having correct hostname at your server.

You can check it by typing hostname

in SSH terminal.

You probably will see something like ubuntu-16gb-nb1-1 or centos-4gb-cl1 etc.

But you must have correct hostname there. Type this command and it will set correct hostname.

hostname yourwebsite.com

After getting correct hostname add newly added one to /etc/hosts.

Open /etc/hosts with

nano /etc/hosts

command and you will see the line like

127.0.1.1 ubuntu-16gb-nb1-1  ubuntu-16gb-nb1-1

Comment or remove that line and add this line instead

127.0.0.1 localhost.localdomain localhost yourwebsite.com

Save it by clicking CTRL+O and that’s all. Test mail() function again, it will work as fast as rocket.

Get more useful WP tricks and snippets by subscribing to my mailclub.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.