skip to Main Content

I am having issues with embedding a html body into my WordPress mail. As of now I have tried multiple code snippets and none seem to work.

What I am seeing right now is, that the email is being sent correctly, but the html code is typed in as text and not being displayed as html content.

I have included my code below

// Get the Customer billing email
$billing_email  = $order->get_billing_email();
$subject = 'Your Email Subject';

 // Message
 $message = '
 <html><body><p>Here are the birthdays upcoming in August!</p></body></html>
';

// To send HTML mail, the Content-type header must be set
$headers = array('Content-Type: text/html; charset=UTF-8');


wp_mail( $billing_email, $subject, $message );

I tried using some other code snippets I found on stackoverflow, and none of them have worked

Can anyone help me out?

2

Answers


  1. Chosen as BEST ANSWER

    This code now works I just needed to change the content type from text to html.

      // Get the Customer billing email
    $billing_email  = $order->get_billing_email();
    $subject = 'Your Email Subject';
    
     // Message
     $message = '
     <html><body><p>Here are the birthdays upcoming in August!</p></body></html>
    ';
    
    // To send HTML mail, the Content-type header must be setremove_filter( 'wp_mail_content_type', 'set_html_content_type' );
    add_filter( 'wp_mail_content_type', 'set_html_content_type' );
    function set_html_content_type() {
    
        return 'text/html';
    }
    
    
    wp_mail( $billing_email, $subject, $message );
    

  2. I think, you missed headers to add wp_mail function call. You declared but not used.

    $to = '[email protected]';
    $subject = 'The subject';
    $body = 'The email body content';
    $headers = array( 'Content-Type: text/html; charset=UTF-8' );
     
    wp_mail( $to, $subject, $body, $headers );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search