我已经为这个脚本苦苦挣扎了 5 天,但我无法让它工作。我想使用 php 邮件功能发送邮件。它需要有一个内联图像和 2 个附件。我所拥有的就是这样,它在 Thunderbird 中显示正确,但在 Gmail 客户端中,它将图像显示为附件,而不是在邮件正文中。这是我的代码:
<?php
$filename = "sharewood-lija-cjenik.xlsx";
$filename2 = "sharewood-lija-ponuda.pdf";
$inline = chunk_split(base64_encode(file_get_contents('../img/sharewoodlija.png')));
$sep = sha1(date('r', time()));
$uid = md5(uniqid(time()));
$subject = "Sharewood Lija";
$mailto = "mymail@gmail.com";
$message = '<img src="cid:image_identifier" alt="SWLBanner" /><br><br>';
$message .="<div>html message</div>";
$header = "From: asdf <asdf@asdf.hr>\r\n";
$header .= "Reply-To: asdf@asdf.hr\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/related; 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/html; charset=uft-8\r\n";
//$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
//image
$header .= "--".$uid."\r\n";
$header .= "Content-Type: image/png;\r\n";
$header .= "name=\"sharewoodlija.png\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-ID: <image_identifier>\r\n";
$header .= "Content-Disposition: inline;\r\n";
$header .= "filename=\"sharewoodlija.png\"\r\n\r\n";
$header .= $inline."\r\n";
//cjenik
$file = "../cjenik/sharewood-lija-cjenik.xlsx";
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$name = basename($file);
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; name=\"".$filename."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
//ponuda
$file2 = "../cjenik/sharewood-lija-ponuda.pdf";
$file_size2 = filesize($file2);
$handle2 = fopen($file2, "r");
$content2 = fread($handle2, $file_size2);
fclose($handle2);
$content2 = chunk_split(base64_encode($content2));
$name2 = basename($file2);
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/pdf; name=\"".$filename2."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename2."\"\r\n\r\n";
$header .= $content2."\r\n\r\n";
$header .= "--".$uid."--";
if (mail($mailto, $subject, "", $header)) {
echo "mail send ... OK"; // or use booleans here
} else {
echo "mail send ... ERROR!";
}
?>
任何帮助表示赞赏