几天来,我一直在总结这样一个事实:我可以创建一个发送 HTML 邮件模板的脚本,如果用户的客户端无法读取 HTML,纯文本列表可能无法接收 HTML 电子邮件。
请一些关于如何做到这一点的通用建议。我查遍了整个互联网,但我真的不知道。
非常感谢您的建议。
您应该添加名为的电子邮件的 html 和纯文本版本multipart/alternative
在同一电子邮件正文中:
<?php
$from = "a asd";
$email = "[email protected] /cdn-cgi/l/email-protection";
$email = "[email protected] /cdn-cgi/l/email-protection";
$semi_rand = md5(time());
$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";
$mime_boundary_header = chr(34) . $mime_boundary . chr(34);
$boundary = "nextPart";
$headers = "From: \"".$from."\" <".$email.">\n";
$headers .= "To: ". $new_to ."\n";
$headers .= "Reply-To: \"". $from. "\" <" . $email . ">\r\n";
$headers .= "Return-Path: <". $email .">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/alternative;\n boundary=" . $mime_boundary_header ;
$headers .= "\n--$boundary\n"; // beginning \n added to separate previous content
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "\n--$boundary\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding:base64\r\n";
$body = "
--$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
". strip_tags($messageBody) ."
--$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding:base64
". chunk_split(base64_encode($messageBody)) ."
--$mime_boundary--";
mail(null,$sub,$body,$headers,"-f".$email);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)