WordPress以.HTML附件形式发送电子邮件内容

时间:2018-12-03 21:43:32

标签: php wordpress html-email email-attachments

我有一封电子邮件,其中包含HTML内容,不适合电子邮件标准。这意味着它具有在电子邮件标准中无效的标记。

我需要将此content / PHP变量作为HTML文件而不是作为电子邮件正文内容发送。我正在使用wp_mail。我只是想采用$ template变量,使其以某种方式使其成为html文件并发送出去。下面是我正在使用的简单wp_mail函数。再次,我需要使用$ template变量,并以某种方式从中生成HTML文件。

file_put_contents不能选择。

wp_mail($to, $subject, $template, $headers, $mail_attachment);

2 个答案:

答案 0 :(得分:0)

怎么样 $ myfile = fopen('myHTMLFile.html','w');

然后使用fwrite()将内容放入其中并发送。

答案 1 :(得分:0)

您可以考虑wp_upload_bits创建模板文件,因为wp_mail仅接受附件文件:

$html_file = wp_upload_bits('test.html', null, $template);

,然后调用wp_mail发送附带的html:

wp_mail($to, $subject, 'your message', array('Content-Type: text/html; charset=UTF-8;'), array($html_file['file']) );

不要忘记检查$html_file对象,$html_file['error']必须为false。

最后,您可以从服务器删除文件:

unlink( $html_file['file'])

希望这会有所帮助!

相关问题