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);