vendredi 27 février 2015

Using WordPress to send html mails with the smtp plugin

I want to send html mails to my users when they are going to sign up in my site and I have written these codes in the function "wp_new_user_notification".



$message = '<html><body>';
$message .= '<img src="//liux.so/mail/pic.jpg" alt="\r\n" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>username:</strong> </td><td>" . strip_tags($user->user_login) . "</td></tr>";
$message .= "<tr><td><strong>password:</strong> </td><td>" . strip_tags($plaintext_pass) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";


After sending a test mail to my own mailbox, I was surprised to see that the whole mail is full of html codes! And then I search this issue on Google. It says that I should add "header" in front of "message". Just like...



mail($to, $subject, $message, $headers);


So the question is over here! I've installed a plugin which allows me to send mails through the smtp service. And this plugin should write the code like this...



wp_mail($user->user_email, sprintf(__('[%s] Welcome!”'), $blogname), $message);


I cannot figure out how to put the "header" into "wp_mail" function or just make the html codes work...


Aucun commentaire:

Enregistrer un commentaire