Acorn mail headers overwrite

I have a Livewire contact form with Acorn Mail setup. I’m trying to set the users name and email as the one who has sent the message. But when using $headers to dynamically set the mail from and name in wp_mail(), it is always what I have supplied inside the .env for mail_from_address & name. It seems the headers get overwritten but mail_from is mandatory or the mailer won’t be setup. Is there a way to get around this behavior?

$to = env('MAIL_FROM_ADDRESS');
$subject = $this->subject;
$body =  nl2br(esc_html($this->message));

$headers = [
   'Content-Type: text/html; charset=UTF-8',
   'From: ' . $this->name . ' <' . $this->email . '>'
];

$mail_sent = wp_mail($to, $subject, $body, $headers);

[quote=“Broder, post:1, topic:29250”]
If the SMTP plugin forces the From address but allows Reply-To, you can try this:


$to = env('MAIL_FROM_ADDRESS');
$subject = $this->subject;
$body = nl2br(esc_html($this->message));

$headers = [
    'Content-Type: text/html; charset=UTF-8',
    'Reply-To: ' . $this->name . ' <' . $this->email . '>'
];

$mail_sent = wp_mail($to, $subject, $body, $headers);

now the email will still be sent from the configured MAIL_FROM_ADDRESS, but when the recipient clicks “Reply,” it will go to the actual sender’s email ($this->email).

1 Like

This is a good enough solution, thank you!