php mail函数 附件,[php]mail函数发送邮件(正文+附件+中文)
$from = "xxx@xxx.cn";
$to = "xxx@xxx.cn, xxx@xxx.com";
$subject = "郵件主題";
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
$attach_filename = date("Y-m-d") . ".html";
$emailBody = "
正文第一行
正文第二行
正文第三行
The end!";
# 然后我們要作為附件的HTML文件
$attachment = "
The attached fileThis is the attached HTML file
";
$boundary = uniqid("");
$headers = "From: $from
To: $to
Content-type: multipart/mixed; boundary=\"$boundary\"";
$emailBody = "--$boundary
Content-type: text/plain; charset=utf-8
Content-transfer-encoding: 8bit
$emailBody
--$boundary
Content-type: text/html; name=$attach_filename
Content-disposition: inline; filename=$attach_filename
Content-transfer-encoding: 8bit
$attachment
--$boundary--";
mail("xxx@xxx.cn", $subject, $emailBody, $headers);
?>
按照上例是能發送成功, 但項目中真正使用時, 卻出現了亂碼的問題:
當正文或附件html一行很長的時候, 收到的內容有亂碼和!等異常, ?查閱到有人說html郵件一行不能超過80個字符,抱著試一試的態度,
生成html附件內容字符串的時候用類似?$html .= "
"; ?$html .= "xxx\n";?$html .= "xxxx\n";?$html .= ""; ?的方法, html每增加一點內容,加上 \n.既保證郵件body單行不超過80字符,有保證 不會被wordwrap折斷.經過這么一折騰, 完美解決了亂碼.
啊哈...
總結
以上是生活随笔為你收集整理的php mail函数 附件,[php]mail函数发送邮件(正文+附件+中文)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: dede php 常用,dede cms
- 下一篇: matlab考试湖北理工学院,电子信息工