Sendmail wont work with PHP

mail() test with PHP:

$to = '';

$subject = 'Test email using PHP';

$message = 'This is a test email message';

$headers = 'From:' . "\r\n" .

'Reply-To:' . "\r\n" .

'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers, ''))

echo 'Successfully sent email to queue.';


echo 'Error, mail was not sent to queue.';



Successfully sent email to queue.

tail -f /var/log/maillog:

Jun 26 21:32:38 sr2 postfix/smtp[5121]: connect to ASPMX2.GOOGLEMAIL.COM[]:25: Connection timed out

Jun 26 21:32:38 sr2 postfix/smtp[5121]: 9307840CEF: to=<>, relay=none, delay=790, delays=640/0.01/150/0, dsn=4.4.1, status=deferred (connect to ASPMX2.GOOGLEMAIL.COM[]:25: Connection timed out)

Jun 26 21:32:38 sr2 postfix/smtp[5122]: connect to[]:25: Connection timed out

How do I force it to use port 587?

2 Replies

Include ":587" at the end of the relayhost configuration setting.

This howto gives a relatively straightforward explanation of sending outbound mail via Gmail. You can probably find others out there that are specific to your distro and version.

Worked. Even with unauthenticated sender emails. I did have to turn off sendmail, and turn on postfix.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct