Recently got a request to configure wordpress plugin to send html email using the native wp_mail() function. The main purpose is to beautify the email layout with some colourful content. So i dig into the wordpress codex and i managed to find a filter that helps to configure the email content type from ‘text/plain’ to ‘text/html’. Meaning, i can easily configure the wp_mail() function to send html email!
To send html email using wp_mail() function, try out the code below:-
Advertisements
- By configure the filter for ‘wp_mail_content_type’, it can direct wp_mail() function to send html email.
-
123456789add_filter( 'wp_mail_content_type', 'set_html_content_type' );wp_mail( 'sendto@thisemail.com', 'The subject', '<p>The <em>HTML</em> content here</p>' );remove_filter( 'wp_mail_content_type', 'set_html_content_type' );function set_html_content_type() {return 'text/html';}
- Remember to remove the filter (at line 5), this is to avoid any conflict between plugins.
Happy Emailing!
Related posts:
Prestashop 1.6: "Unexpected token <" error when upload category thumbnail
Composer: PHP Fatal error: Allowed memory size of ... exhausted...
WordPress: How to upload image using script?
How to create mailing list in Thunderbird
How to change 'Out of Stock' text in Woocommerce
WordPress: How to create left sidebar template in TwentyEleven theme?
WordPress: How to open rss links in new window?
WordPress Plugin Dev: How to send email using SMTP?
Share this with your friends:-