Search code examples
wordpresscontent-typemultipart-alternative

Content-Type: multipart/alternative in Wordpress with wp_mail()


Is it is possible to send emails with the wp_mail() function having its Content-Type: multipart/alternative ?

I need to send emails that can be shown as HTML or Plain Text depending on what medium interprets the email.

Any suggestions are welcome!


Solution

  • It's right there in the wp_mail() documentation (under Usage):

    The default content type is 'text/plain' which does not allow using HTML. You can set the content type of the email either by using the 'wp_mail_content_type' filter (see example below), or by including a header like "Content-type: text/html". Be careful to reset 'wp_mail_content_type' back to 'text/plain' after you send your message, though, because failing to do so could lead to unexpected problems with e-mails from WP or plugins/themes.

    (emphasis mine)

    The 2nd example on the page shows you how to do it (the example uses text/html but you should be able to use your multipart/alternative instead.