Skip to main content
added 9 characters in body; edited title
Source Link
butlerblog
  • 5.1k
  • 3
  • 26
  • 42

Include HTML template file in wp mailwp_mail

I'm using wp mailwp_mail() to send an htmlHTML email. But there's quite a lot of htmlHTML code in the email, so rather than including all the code in my wp mailwp_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 htmlHTML 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.

Include HTML template file in wp mail

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.

Include HTML template file in wp_mail

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.

added 2 characters in body
Source Link
Xav
  • 399
  • 1
  • 9
  • 23

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 = person@gmail'person@gmail.comcom' ;
   $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.

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 = person@gmail.com ;
   $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.

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 = 'person@gmail.com' ;
   $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.

Source Link
Xav
  • 399
  • 1
  • 9
  • 23

Include HTML template file in wp mail

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.