I have correctly set the postfix server according to PHP+Ubuntu Send email using gmail form localhost, so that this msmtp sends the email via:
$ echo -e "Subject: Test Mail\r\n\r\nThis is my first test email." |msmtp --debug --from=default -t [email protected]
/etc/msmtprc
account default
host smtp.gmail.com
port 587
auth on
user [email protected]
password *********
from [email protected]
logfile /var/log/msmtp.log
`$ls -l /etc/msmtprc
-rw-rw-r-- 1 www-data www-data 377 Aug 30 12:54 /etc/msmtprc
which works correctly (the defaul account is set in /etc/msmtprc
. Then I have set the sendmail_path
in /etc/php/7.3/apache2/php.ini
:
sendmail_path = /usr/bin/msmtp -t
So I tried to execute an example from php manual - mail :
<?php
$to = '[email protected]';
$sub = 'the subject';
$mes = 'hello';
$header = 'From: [email protected]\r\n'; //not even needed - the default account is set
mail($to, $sub, $mes, $header);
But I can't find the email in the address [email protected]
. What I did wrong? it should be set according to that answer.
Edit: tried to trigger the execution with root according to this Sending mail through terminal using msmtp works fine, but doesn't work with php mail(), yet no success.
Edit2:
It got even more stranger. From 15 test sending (15*execution of php script), 2 mails really arived. But they were from "unknown-sender", where the sender should be default account specified in /etc/msmtprc
and even specified in the php in header From:...
. I am really confused, what is going on here.