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 plain text?
Any ideas?
from wp_mail codex page:
As an alternative, you can specify the Content-Type HTTP header in the $headers parameter:
Don’t forget to remove the content type filter after you use the wp_mail function.
Following the accepted answer naming you should do this after wp_mail is executed:
Check this ticket here – Reset content-type to avoid conflicts — http://core.trac.wordpress.org/ticket/23578
Another easy way I’m going to share below. Even you can style your mail body as your wish. Maybe it’s helpful for you.
More about PHP heredoc syntax https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
Use
ob_start
, because this will allow you to use WP variables/functions like bloginfo etc.make a PHP file and paste your HTML in that file(use wp variables inside that php file if needed).
Use the below code:
this will keep your code clean and due to ob_start we will also save the time of loading the file.