Include HTML code in emails sent through WP Mail

Working with Themes and Plugins may require you to use tools like wp mail to send group email to multiple users. Definitely given the standards we are accustomed to today by getting emails, you need to include the HTML code that is correctly displayed for aesthetics of the final message.

On wordpress, in order to send formatted emails with text and html, you need to include within the functions.php the following code:

[code]add_filter( ‘wp_mail_content_type’, ‘wpdocs_set_html_mail_content_type’ );
function wpdocs_set_html_mail_content_type() { return ‘text/html’; }[/code]

and then before calling up the function, you need to set the mail headers like this:

[code]
$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 );
[/code]

After you have successfully entered this code you will be able to send emails using the html and css code to improve mail style.


Commenti

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.