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> </p>
<p>Some text.</p>
<p> </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
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 );