Sending HTML email with attachment with wp_mail()

This one should be easy, but I can’t figure it out.
I want to send an email that is HTML formatted, but also has an attachment. The attachment is being sent correctly, but the message is delivered as plaintext, like this:

<p>Hello!</p>
<p>&nbsp;</p>
<p>Some text.</p>
<p>&nbsp;</p>
<p>Best wishes,</p>
<p>Team</p>

If it was an email without attachment, I would force it to send html by changing the header as described here. But now I need the content type to be multipart / mixed (right?). So my question is: how do I convince wp_mail() to send my messages as html, and include the attachment?

3 Answers
3

Reference link click here.

Using below code you can send the mail with html format.

$to = 'sendto@example.com';
$subject="The subject";
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');

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

// For attachment 

$attachments = array( WP_CONTENT_DIR . '/uploads/file_to_attach.zip' );
$headers="From: My Name <myname@example.com>" . "\r\n";

wp_mail( 'test@example.org', 'subject', 'message', $headers, $attachments );

Leave a Comment