Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php takes 1+ minute to send mail with sendmail & maildev

Maildev is running with

maildev -s 25

PHP is setup with

[mail function]
SMTP = 127.0.0.1
smtp_port = 25

When I try to send mail (with PHPMailer), I see that sendmail is running:

0784 www-data   20   0  4508   748   672 S  0.0  0.0  0:00.00 sh -c /usr/sbin/sendmail -t -i  -oi [email protected]

And after about ~2mn, that process ends and mails are sent to Maildev.

I don't understand why mails are not directly sent to Maildev...

like image 403
Hugo H Avatar asked May 08 '17 07:05

Hugo H


People also ask

Why does PHP mail take so long?

It is the SMTP mail delivery (which PHP hands off the message to) which is taking time. Possibly, the delay you see is greylisting on the receiving server, meaning that the receiving mail server refuses to accept the message until the sending server (which your PHP script handed it to) tries a few times.

Why is sendmail slow?

The most common reason for slow sendmail startup is DNS not resolving.

Does PHP mail use sendmail?

Introduction. PHP comes with a default function mail() that allows you to sendmail directly from a PHP script.

Which is better sendmail or SMTP?

Some mail programs (most, today) will connect directly to a mail server and speak SMTP to it. However, the "traditional" method - and arguable the better method - is to let sendmail do it.


1 Answers

I finally found it!

In my /var/logs/mail.log I had this error log:

My unqualified host name (hugo) unknown; sleeping for retry

Then 1 minute later :

Unable to qualify my own domain name (hugo) -- using short name

I fixed this error with https://askubuntu.com/a/436270/510570, by:

Setting a good FQDN in my /etc/hosts file:

127.0.0.1 hugo.example.com hugo 

And applying it:

sudo hostname hugo.example.com
like image 126
Hugo H Avatar answered Sep 26 '22 09:09

Hugo H