【发布时间】:2019-12-26 07:25:49
【问题描述】:
这是我的代码
$to = $to;
$from = $from;
$subject = $subject;
$file = "example_file.pdf";
$htmlContent = "message goes here";
$headers = "From: "." <".$from.">";
//boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
//multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n";
//preparing attachment
if(!empty($file) > 0){
if(is_file($file)){
$message .= "--{$mime_boundary}\n";
$fp = @fopen($file,"rb");
$data = @fread($fp,filesize($file));
@fclose($fp);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: application/octet-stream; name=\"".basename($file)."\"\n" .
"Content-Description: ".basename($file)."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".basename($file)."\"; size=".filesize($file).";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $from;
//send email
$mail = @mail($to, $subject, $message, $headers, $returnpath);
//email sending status
return $mail ? true : false;
我正在为我的项目使用上面的代码。
发送不带附件的电子邮件时效果很好,但带有附件的所有电子邮件都会变成垃圾邮件和垃圾邮件
帮我解决问题。
【问题讨论】:
-
我在发送不带附件的邮件时没有任何问题。我只有在发送带有附件的电子邮件时才会遇到问题。如果你能帮我@mario
-
没有展示一些研究就没有“帮助我”或解决方案。阅读链接的参考资料,使用其中一项检查服务;并且只有然后修复您的手动 MIME 构造 copypasta(或使用适当的库)。