为了让生活变得困难,我正在努力的客户使用的是一个在
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的电子邮件,并为其添加附件.我确定我在这里错过了一些非常简单的东西!
提前致谢.
好的,我终于搞砸了!以供参考:
原文链接:https://www.f2er.com/php/134646.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);