脚本宝典收集整理的这篇文章主要介绍了使用mail()在PHP4的电子邮件中发送附件AND text / html,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试通过PHP发送一封包含附件和附带的text / html内容的电子邮件,但我无法通过一封电子邮件发送这两封内容.
这会发送附件:
$headers = "Content-Type: text/csv;\r\n name=\"result.csv\"\r\n Content-transfer-encoding: base64\r\n Content-Disposition: attachment\r\n boundary=\"PHP-mixed-".$random_hash."\""; $output = $attachment; mail($emailTo,$emailSubject,$output,$headers);
这发送text / html:
$headers = "Content-Type: text/html; charset='iso-8859-1'\r\n"; $output = $emailBody; // $emailBody contains the HTML code.
这会发送包含text / html的附件以及附件内容:
$headers = "Content-Type: text/html; charset='iso-8859-1'\r\n".$emailBody."\r\n"; $headers = "Content-Type: text/csv;\r\n name=\"result.csv\"\r\n Content-transfer-encoding: base64\r\n Content-Disposition: attachment\r\n boundary=\"PHP-mixed-".$random_hash."\""; $output = $attachment;
我需要知道的是如何在电子邮件正文中发送带有text / html的电子邮件,并为其添加附件.我确定我在这里错过了一些非常简单的东西!
提前致谢.
$emailBody .= "<html><body>Blah</body></html>"; $emailSubject = "Subject"; $emailCSV = "\"Col1\",\"Col2\"\r\n"; // etc. $attachment = $emailCSV; $boundary = md5(time()); $header = "From: Name <address@address.com>\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed;boundary=\"" . $boundary . "\"\r\n"; $output = "--".$boundary."\r\n"; $output .= "Content-Type: text/csv; name=\"result.csv\";\r\n"; $output .= "Content-Disposition: attachment;\r\n\r\n"; $output .= $attachment."\r\n\r\n"; $output .= "--".$boundary."\r\n"; $output .= "Content-type: text/html; charset=\"utf-8\"\r\n"; $output .= "Content-transfer-encoding: 8bit\r\n\r\n"; $output .= $emailBody."\r\n\r\n"; $output .= "--".$boundary."--\r\n\r\n"; mail($emailTo,$header);
以上是脚本宝典为你收集整理的使用mail()在PHP4的电子邮件中发送附件AND text / html全部内容,希望文章能够帮你解决使用mail()在PHP4的电子邮件中发送附件AND text / html所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。