Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wordpress wp_mail is sending my html message as a text attachment

Tags:

wordpress

This is the code to send the mail:

$to = $_POST['leadEmail'];
$subject = "my subject";
$message = ( $_POST['leadEmailPref'] == "html" ) ? $messageh : $messagep ;
$headers[] = "From: My Name <[email protected]>";
$headers[] = "Content-type: ".$_POST['leadEmailPref'] ;

wp_mail( $to, $subject, $message, $headers );

When I go to my inbox, the message is sent as an attachment and I don't see the message. Obviously I don't want the attachment, and I want the person who receives the email to see the message immediately.

like image 612
Lawrence DeSouza Avatar asked Dec 26 '22 00:12

Lawrence DeSouza


1 Answers

Your Content-type: is wrong. It should be text/html or text/plain, not html.

$headers[] = "Content-type: text/".$_POST['leadEmailPref'] ;

like image 65
Nadh Avatar answered Apr 08 '23 18:04

Nadh