日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php mail函数 附件,[php]mail函数发送邮件(正文+附件+中文)

發布時間:2025/4/17 php 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 file

This 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函数发送邮件(正文+附件+中文)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。