2

I have the following config file for msmtp

account         default
host         SES_HOST
port         587
timeout         5
auth         on
tls          on
tls_starttls    on
tls_trust_file     /etc/ssl/certs/ca-certificates.crt
syslog          on
set_from_header on
allow_from_override off
user         SES_USERNAME
password     SES_PASSWORD
from         SES_VERIFIED_EMAIL

php.ini

sendmail_path = /usr/local/bin/msmtp -ti

I want to make sure all emails sent via php use the SES_VERIFIED_EMAIL in the from header so SES does NOT reject the email. I thought setting the from allow_from_override on and allow_from_override off would mean that email send from php with a from header that is NOT SES_VERIFIED_EMAIL would be replaced by SES_VERIFIED_EMAIL so the message will be sent

But I can only send emails via php where the from header is already put in as SES_VERIFIED_EMAIL but I need it to work in all cases. It doesn't appear the from header is being replaced

I want msmtp to override the From header to SES_VERIFIED_EMAIL so it does get sent. I thought the settings above would do it.

<?php
    $to      = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: NOTSESVERIFYED@example.com'       . "\r\n" .
                 'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);
?>
Chris Muench
  • 17,444
  • 70
  • 209
  • 362

2 Answers2

2

Change:

set_from_header on

To:

set_from_header off
Dan M
  • 4,340
  • 8
  • 20
0

Try:

from               SES_VERIFIED_EMAIL
rewrite_domain     SES_VERIFIED_EMAIL

The rewrite_domain option is used to rewrite the domain part of the From header. This is useful if you want to send mail from a domain that is not your own. The domain part of the From header is rewritten to the value of the rewrite_domain option. The local part of the From header is not changed.

Tibic4
  • 3,709
  • 1
  • 13
  • 1
    I need local part to also be rewritten otherwise SES won’t send. I don’t understand why what I have isn’t working. Is ‘from’ NOT the from header? – Chris Muench Oct 07 '22 at 15:10