Forums

wp_mail_content_type (7 posts)

  1. jpksilversand
    Member
    Posted 2 years ago #

    I'm working on a plug in that uses the wp_mail function and need to send HTML e-mail (rather than plain text e-mail).

    The documentation on wp_mial in the Codex notes that you can use the

    wp_mail_content_type

    filter to send HTML email, but there is no information on how to do this.

    Can anybody provide sample code or outline how to use this filter?

    Thanks!

  2. F J Kaiser
    Member
    Posted 1 year ago #

    This is the hook in source/core, but i couldn“t get around it. If you solve it, pls post back your sollution. Thanks!

  3. F J Kaiser
    Member
    Posted 1 year ago #

  4. dalehurley
    Member
    Posted 1 year ago #

    Hi Guys

    There is the filter for content type though I have never got it to work or find anyone who has got it to work. Instead the the trick is to build a custom header with the MIME, Content Type. Below is an example.

    $headers= "MIME-Version: 1.0\n" .
            "From: Me <dale.hurley@example.com>\n" .
            "Content-Type: text/html; charset=\"" .
    get_option('blog_charset') . "\"\n";
    wp_mail($emailaddress, $subject, $content, $headers);

    Dale
    CreateMy.com.au

  5. c4isbad
    Member
    Posted 1 year ago #

    I know this is a little late, but it could be useful

    before you send your wp_mail call add a filter to wp_mail_content_type

    add_filter('wp_mail_content_type','set_contenttype');

    then in your set_contenttype function have it return the appropriate content type, in this case 'text/html'

    function set_contenttype($content_type){
    return 'text/html';
    }

    works for me

  6. Andy Potanin
    Member
    Posted 1 year ago #

    Same end-result, but less code:

    <?php 
    
    add_filter('wp_mail_content_type',create_function('', 'return "text/html"; '));
    
    wp_mail('whoever@whatever.com', 'Subject', 'Message');
    ?>
  7. theblakereport
    Member
    Posted 1 year ago #

    Andy, very helpful, thank you

Topic Closed

This topic has been closed to new replies.

About this Topic