Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there an action_hook or something similar that could help me achieve this?

I tried adding markup in a PHP string variable and just fired off an email with the wp_mail function like so:

$email_to = 'someaddress@gmail.com';
$email_subject = 'Email subject';
$email_body = "<html><body><h1>Hello World!</h1></body></html>";
$send_mail = wp_mail($email_to, $email_subject, $email_body);

But it showed up as plaintext?

Any ideas?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

from wp_mail codex page:

The default content type is 'text/plain' which does not allow using HTML. However, you can set the content type of the email by using the 'wp_mail_content_type' filter.

function wpse27856_set_content_type(){
    return "text/html";
}
add_filter( 'wp_mail_content_type','wpse27856_set_content_type' );
share|improve this answer
    
Hmm sounds useful. Just a question, any particular reason why you named your function wpse27856_set_content_type? –  racl101 Sep 6 '11 at 21:31
    
No, it's just a unique name based on the id of this particular question. wpse = wp stachexchange, 27856 is the id of this question in the URL. I just do that to avoid potential collisions if people copy/paste code out of here. –  Milo Sep 6 '11 at 21:45
    
You can also just include the Content-Type in your email headers. Check out how the Notifly plugin does it. –  Otto Sep 7 '11 at 0:29
    
oh yeah, ha ha. What a n00b I am. Guess it is the id of this post. –  racl101 Sep 7 '11 at 7:44
    
Should the email be a .txt file or a .html file? I'm using this method but if I view source it is a .txt file and the embedded image is not processed. –  AlxVallejo Jul 27 '12 at 23:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.