gpt4 book ai didi

PHP : email sending failed with more than one attachment

转载 作者:可可西里 更新时间:2023-11-01 13:30:41 24 4
gpt4 key购买 nike

我正在尝试在 php 中实现邮件功能,它可以很好地处理单个附件,但问题是当我尝试发送多个附件时,它不起作用。我正在使用 php mail() 函数发送电子邮件,我正在尝试附加 PDF 和图像文件。如果附加 PDF,则不会附加图像,如果附加图像,则不会附加 PDF。有什么想法我做错了吗?

$header       .= 'From: test <noreply@test.ae>' . "\r\n";       
$header .= "MIME-Version: 1.0\r\n";
$file = '1.png'
$displayname = '1.png';
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);

$filepdf = '1.pdf'
$displaynamepdf= '1.pdf';
$file_sizepdf = filesize($filepdf);
$handlepdf = fopen($filepdf, "r");
$contentpdf = fread($handlepdf, $file_sizepdf);
fclose($handlepdf);
$contentpdf = chunk_split(base64_encode($contentpdf));
$name = basename($file);

$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$displayname."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$displayname."\"\r\n\r\n";
$header .= $content."\r\n\r\n";

$header .= "Content-Type: application/octet-stream; name=\"".$displaynamepdf."\"\r\n"; // use different contentpdf types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$displaynamepdf."\"\r\n\r\n";
$header .= $contentpdf."\r\n\r\n";
$header .= "--".$uid."--";

if (mail($to, $subject, "", $header)) {
return 'sent';
} else {
return 'not sent';
}

最佳答案

关于PHP : email sending failed with more than one attachment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15426236/

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