I haven't seen an example sending email containing both html and plain text using wp_mail function.


Do you mean to send a plain text version along-side the HTML version?

If so I found this page helpful in setting it up:

The crux of it comes down to this:

 //create a boundary for the email. This 
 $boundary = uniqid('np');

 //headers - specify your from email address and name here
 //and specify the boundary for the email
 $headers = "MIME-Version: 1.0\r\n";
 $headers .= "From: Your Name \r\n";
 $headers .= "To: ".$email."\r\n";
 $headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";

 //Plain text body
 $message .= "Hello,\nThis is a text email, the text/plain version.
 \n\nRegards,\nYour Name";
 $message .= "\r\n\r\n--" . $boundary . "\r\n";
 $message .= "Content-type: text/html;charset=utf-8\r\n\r\n";

 //Html body
 $message .= "
 This is the html version.

 Your Name";
 $message .= "\r\n\r\n--" . $boundary . "--";

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.