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!
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!
You must be logged in to post a comment.
It’s right there in the
wp_mail()
documentation (under Usage):(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 yourmultipart/alternative
instead.It’s totally possible when you have access to the phpmailer instance.
The message sent to wp_mail should be your html code. You also shouldn’t include any content type headers. I currently use from, cc and reply-to in the plugin i’ve made.
If the email is being sent as HTML, I run the action which sets the AltBody property on the phpmailer object directly. This then causes the proper flags to convert the email to a multipart/alternative email.
You can use the wp_mail_content_type filter, which was now been documented in the Codex.
The wp_mail documentation about resetting the content type back to ‘text/plain’ is kind of misleading, IMO. Since this is a filter, you don’t really “reset” it. What you need to consider in your filter is some conditional logic to determine when you need to use multipart vs. plain text or html: