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

歡迎訪問 生活随笔!

生活随笔

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

php

php 发送带附件的邮件,php发送带附件的电子邮件

發布時間:2025/4/16 php 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 发送带附件的邮件,php发送带附件的电子邮件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我似乎無法找到這個我寫的php函數的問題,應該發送帶附件的電子郵件.我已經掙扎了很長一段時間.

function myMail($to, $subject, $mail_msg, $filename, $contentType){

$random_hash = md5(date('r', time()));

$headers = "From: webmaster@example.com\r\nReply-To: ".$to;

$headers .= "\r\nContent-Type: ".$contentType.

"; boundary=\"PHP-mixed-".$random_hash."\"";

$attachment = chunk_split(base64_encode(file_get_contents($filename)));

ob_start();

echo "

--PHP-mixed-$random_hash

Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"

--PHP-alt-$random_hash

Content-Type: text/plain; charset=\"utf-8\"

Content-Transfer-Encoding: 7bit

$mail_msg

--PHP-alt-$random_hash

--PHP-mixed-$random_hash--

Content-Type: text/plain; name=\"$filename\"

Content-Transfer-Encoding: base64

Content-Disposition: attachment

$attachment

--PHP-mixed-$random_hash--

";

$message = ob_get_clean();

$mail_sent = @mail( $to, $subject, $message, $headers );

return $mail_sent ? "Mail sent" : "Mail failed";

}

編輯問題是郵件的消息與文件混合并作為附件發送.

解決方法:

我剛剛查看了幾封電子郵件,并注意到最終的附件邊界以’ – ‘結尾,而開放邊界標記則沒有.在您的代碼中,您有:

--PHP-mixed-$random_hash--

Content-Type: text/plain; name=\"$filename\"

Content-Transfer-Encoding: base64

Content-Disposition: attachment

$attachment

--PHP-mixed-$random_hash--

也許它應該是:

--PHP-mixed-$random_hash

Content-Type: text/plain; name=\"$filename\"

Content-Transfer-Encoding: base64

Content-Disposition: attachment

$attachment

--PHP-mixed-$random_hash--

看看這里的例子:

標簽:php,email,attachment

來源: https://codeday.me/bug/20190916/1807848.html

總結

以上是生活随笔為你收集整理的php 发送带附件的邮件,php发送带附件的电子邮件的全部內容,希望文章能夠幫你解決所遇到的問題。

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