R
R
Roma2018-07-09 12:19:48
PHP
Roma, 2018-07-09 12:19:48

Why might mail() not work?

Why might the php mail() function not work?
server on centos, msmtp installed, exchange mail server, PHP 5.6.33
when sent from console with
echo "Testing" | mail -s "Test" [email protected]
php -r "mail('[email protected]', 'Test', 'Test');"
both letters reach, when sending from the site, nothing is written to the log;
verification of sending from the site is performed by such a file

$sender = '[email protected]';
$recipient = '[email protected]';

$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;

if (mail($recipient, $subject, $message, $headers))
{
    echo "Message accepted";
}
else
{
    echo "Error: Message not accepted";
}

did not find anything in .htaccess, where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roma, 2018-07-09
@aaallllsss

I'm dumb.
due to the fact that the site runs under the apache user, and I made the config under root,
you need to override sendmail_path = msmtp -C /home/msmtp/.msmtprc -t -i
copy the finished config /root/.msmtprc to /home/msmtp/. msmtprc and make the file owned by apache with permissions 600

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question