• 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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • This is the hook in source/core, but i couldn´t get around it. If you solve it, pls post back your sollution. Thanks!

    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

    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

    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');
    ?>

    Andy, very helpful, thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘wp_mail_content_type’ is closed to new replies.