Categorie
Wordpress

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:

add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' ); 
function wpdocs_set_html_mail_content_type() { return 'text/html'; }

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

$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 );

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

RPCreative

Di RPCreative

Sono Riccardo Andronaco, un siciliano appassionato di tecnologia e web che scrive articoli su questo blog con il fine di poter condividere con voi le mie esperienze personali e discutere a proposito delle mie opinioni personali. #becreative

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.