使用mail()在PHP4的电子邮件中发送附件AND text / html

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了使用mail()在PHP4的电子邮件中发送附件AND text / html脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
为了让生活变得困难,我正在努力的客户使用的是一个PHP4.0上运行的非常大的旧系统,他们不想添加任何额外的库.

我正在尝试通过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,请注明来意。
标签: