I'm using wp_mail()
to send an HTML email. But there's quite a lot of HTML code in the email, so rather than including all the code in my wp_mail()
function, is it possible to have the code in a separate template and just include this template in the function? Here is what I have:
<?php if ( isset( $_POST['submitted'] )) {
add_filter('wp_mail_content_type',create_function('', 'return "text/html"; '));
$emailTo = '[email protected]' ;
$subject = 'This is the subject';
$body = get_template_part( 'includes/my_email_template' );
$headers = 'From: My Name' . "\r\n";
wp_mail($emailTo, $subject, $body, $headers);
}?>
I'd like to be able to put all of my HTML code in 'my_email_template' but when I try this, no email is sent. Am I including the template incorrectly? Thanks in advance for any answers.
$emailTo = [email protected] ;
try$emailTo = '[email protected]';
.include (TEMPLATEPATH . 'includes/my_email_template.php');
is the correct option?echo
s will just print to the screen rather than get assigned to$body
. I imagine that will cause some errors withwp_mail
as well.