Sendmail wont work with PHP

mail() test with PHP:

$to = 'email@domain.com';

$subject = 'Test email using PHP';

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

$headers = 'From: php-daemon@domain.com' . "\r\n" .

'Reply-To: php-daemon@domain.com' . "\r\n" .

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

if(mail($to, $subject, $message, $headers, '-femail@domain.com'))

echo 'Successfully sent email to queue.';

else

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

?>

Returns:

Successfully sent email to queue.

tail -f /var/log/maillog:

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

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

Jun 26 21:32:38 sr2 postfix/smtp[5122]: connect to alt4.gmail-smtp-in.l.google.com[74.125.131.26]: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.

Reply

Please enter an answer
Tips:

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] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct