skip to Main Content

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      = '[email protected]';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: [email protected]'       . "rn" .
                 'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);
?>

2

Answers


  1. 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.

    Login or Signup to reply.
  2. Change:

    set_from_header on
    

    To:

    set_from_header off
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search