Per my comment to your question, I believe the problem is that include
ing files, whether directly or using get_template_part
isn’t likely to give you a string to pass to $body
and that is going to cause errors in the code, or at the very least unespected behavior.
I would avoid reading files into memory and just create a function that returns your $body
content.
function get_email_body_wpse_96357() {
$body = '<p>Hi</p>';
return $body;
}
Then use $body = get_email_body_wpse_96357();
as needed. An advantage of this method is that you can easily pass parameters to the function if you ever decide to do so. You could also use variables in an included file but it can be messy.
If you don’t want to load that function all the time, then put it in a file by itself and include that file only when you need the function.
Related Posts:
- WP mail sent to MS Exchange recipients = occasional email corruption?
- Images in wp_mail not showing
- Is there a way to embed an iframe in an email with text that updates?
- Sending multipart (text/html) emails via wp_mail() will likely get your domain banned
- How to set SMTP programmatically
- Do something after sending email
- Mail will not send in HTML
- Create custom welcome email without a plugin
- Email sent from WordPress has HTML tags
- Reset Password – change from name and email address
- Few chars getting replaced with ‘=’ in mail content in wp_mail()
- wp_mail recipient array not sending?
- On form submission how to send 2 email to different users
- How to Configure SMTP on wordpress Cant Send Email
- How to add line breaks to $email[‘body’] when using auto_core_update_email hook
- Joining confirmation email
- How to setup SMTP for only one specific wp_mail()
- Must I change the admin user email address while changing the general email address?
- User invite email not delivered – related to subdomain?
- Can I configure WordPress to use postfix without a plugin?
- Email ‘from address’ has a www in it
- Trigger WordPress Actions from Email?
- PHP mail() works but wp_mail() does not
- WordPress unable to send mail
- Not able to send links in email after setting header
- Emailing passwords: Setup installed on home server using XAMPP
- Mail function is not working
- Send bulk emails without timeout
- What is the best way to send out thousands of emails from a WordPress site? [closed]
- Change the Sender(not From) on wp_mail() function [closed]
- Prevent sending emails on user creation in OOP context?
- HTML email sent with wp_mail shows plain text
- WordPress email could not be sent
- Getting image in mail
- Send email daily using `wp_mail`
- wp_mail() won’t send mail when it’s a variable, only when hard coded
- Send email for confirmation during user registration
- About Custom Email Template Design Responsive
- WordPress new user email formatting issues
- Email sent from WordPress has HTML tags
- wp_mail send multiple emails in a loop
- Can’t change headers / From for wp_mail()
- How can I remove the product short description from the WooCommerce Mails?
- New user notification issue
- Why do WordPress emails to multiple recipients include \n in the list
- wp_mail() not sending emails with ajax
- wordpress wp mail not changing sender mail
- Whitelist email sent by WordPress
- WP Mail isn’t sending user account messages, does send from plugins
- Asynchronous emailing
- Send email from WordPress
- Not able to override pluggable function with a mu_plugin
- What is the correct way to send multipart email in wordpress?
- SMTP connect() failed PHPmailer – PHP
- What is the difference between ports 465 and 587?
- User Without Email?
- Using WordPress templating for HTML emails
- Email confirmation on registration
- How do i send mail with custom Form Data using WordPress
- Fwd: [Website Name] Notice of Email Change [closed]
- Send all WPMU emails via SMTP
- How to sent one form values to 2 different sites in wordpress
- General Setting Allow Multiple Email Notification
- wp_mail not sending
- Contact form sender email
- WordPress Add New User – Send an Activation Email
- Send email only upon draft
- Emails marked as spam because it’s contain via box4231.bluehost.com
- How to change the text of automatic E-Mails e.g. after changing your password? (German localization)
- WordPress reset password email is not working – woocommerce and checkmail does work
- User registration email and let user choose pasword
- Correctly configure SPF/DMARC record to work with WordPress [closed]
- Share pdf with a friend via email [closed]
- wp_mail() headers multipart/alternative
- How to set up a simple email subscription?
- How to send post notification when a Author and Contributor post?
- WordPress get_the_content losing formatting when emailed
- Mailing list sign up form without plugin
- WordPress Won’t Send Email When a User Register
- Confirmation required on users email change
- Email address used by website but I do not know where
- wp_mail not sending email on custom function
- Change email address change notice from WordPress
- WP stopped emailing notifications about new comments
- How to change the format of the subcriber email
- I just had an email from wordpress. what does it mean?
- phpmailer reply to message id using AddCustomHeader
- Send email using wordpress plugin on behalf of someone with their permission
- How to apply a function to the value $email of get_user_by to override email_exists?
- E-Mail Notification on post edit
- Sending SMTP mail using a server with self-signed SSL
- Send Custom Post Notification to Followers
- Get emails of register user in WordPress
- MailPress plugin: table inline style tag removed when sending the newsletter
- Display “a generated one [avatar] based on their e-mail address”
- Allow users to register as a higher role than default with code
- Send email once every 12 months to a particular user [closed]
- What’s the simplest way to send WordPress posts to a Mailchimp list? [closed]
- Having Issue on Receiving Emails From @Gmail.com or @Yahoo. in WordPress Using PHP Mail Function
- How to add verification on email address change?