4

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.

2 Answers 2

8

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

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

1
  • 1
    Why aren't you escaping $_POST['leadEmailPref'] ? People could insert extra email headers Jun 2, 2014 at 14:44
2

You should try:

add_filter( 'wp_mail_content_type', 'set_html_content_type' );

wp_mail( 'To Email', 'Subject', '<h1>Html Email</h1>' );

function set_html_content_type() {
    return 'text/html';
}

remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
1
  • how I can attach 1 table with dynamic data into email content ?
    – huykon225
    Apr 8, 2017 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.