gpt4 book ai didi

php发送带附件的邮件

转载 作者:IT王子 更新时间:2023-10-28 23:57:59 27 4
gpt4 key购买 nike

如何发送带有简历附件的邮件,

我从这个地方截取片段Click here

在此站点中,代码段工作正常,

即使我收到了邮件,但附件不起作用,我收到的是 0kb 的 noname

文件大小,该片段中的问题是什么,

最佳答案

 function mail_attachment($to, $subject, $message, $from, $file) {
// $file should include path and filename
$filename = basename($file);
$file_size = filesize($file);
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid = md5(uniqid(time()));
$from = str_replace(array("\r", "\n"), '', $from); // to prevent email injection
$header = "From: ".$from."\r\n"
."MIME-Version: 1.0\r\n"
."Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"
."This is a multi-part message in MIME format.\r\n"
."--".$uid."\r\n"
."Content-type:text/plain; charset=iso-8859-1\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
.$message."\r\n\r\n"
."--".$uid."\r\n"
."Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"
.$content."\r\n\r\n"
."--".$uid."--";
return mail($to, $subject, "", $header);
}

关于php发送带附件的邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4586557/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com