• I’m trying to see if there’s a way to send html email from WordPress. Email function works, but when viewing such email like a notification, I see all the html tags.
    I added add_filter for wp_mail_content_type for ‘text/html’ in the functions.php, it shows on the email header, but I’m still seeing things like <p>, <br>, <style> in the body of the email.

    I’m viewing the email on gmail, it does the same thing in MacOS Mail, as well as Outlook.
    I can work with either a plugin to correctly render html, or just disabling any html tag that WordPress is sending.

    How do I fix this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @perkedel,

    Clearly, this is the issue regarding headers. Please have a look on below snippet :

    $to = ‘[email protected]’;
    $subject = ‘The subject’;
    $body = ‘The email body content’;
    $headers = array(‘Content-Type: text/html; charset=UTF-8’);

    wp_mail( $to, $subject, $body, $headers );

    or please follow this link :
    https://wordpress.stackexchange.com/questions/117359/email-sent-from-wordpress-has-html-tags

    Hope this helps ??

    Thread Starter perkedel

    (@perkedel)

    thanks wpatbest. I do have those lines in my child theme functions.php as described in the stack exchange forum, it just wasn’t working.
    It seems that one plugin that I was using, has the option to enable html email, and that works. So this combination seems to work.

    If I can figure out how to make the other plugins that send email notification, this would be sweet. Unfortunately those plugins don’t have the option to toggle html email like the other.

    In order to see html tag’s effect in email body you must pass correct header type to email. Try to add “Content-Type: text/html; charset=UTF-8” in your email header array.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘html tags in email’ is closed to new replies.