I have an email that has HTML content in it that is not suitable for email standards. Meaning it has markup that is not valid in email standards.
I need to send this content/PHP variable as an HTML file instead of as email body content. I'm using wp_mail. I simply want to take the $template variable and make it an html file somehow and send it off. Below is the simple wp_mail function that I'm using. Again, I need to use the $template variable and somehow generate an HTML file out of it.
file_put_contents is not an option.
wp_mail($to, $subject, $template, $headers, $mail_attachment);
How about $myfile = fopen('myHTMLFile.html', 'w');
And with fwrite() you put your content in it and send it.
You can consider wp_upload_bits
to create the template file since wp_mail
only accepts files for attachments:
$html_file = wp_upload_bits('test.html', null, $template);
and then call wp_mail
to send the html attached:
wp_mail($to, $subject, 'your message', array('Content-Type: text/html; charset=UTF-8;'), array($html_file['file']) );
Don't forget to check the $html_file
object, $html_file['error']
must be false.
Finally you can delete the file from the server:
unlink( $html_file['file'])
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.