我正在使用PHP代码在我的Web应用程序中发送带有附件的邮件。 一切正常,希望Gmail将其标记为垃圾邮件。 我的代码如下所示。
move_uploaded_file($_FILES["file"]["tmp_name"],$path . $_FILES["file"]["name"]);
$filename = $_FILES["file"]["name"];
//$path = "upload/";
$from_name = $_POST['name'];
$from_mail = $_POST['email'];
$mailto = $replyto = "nevinthomas153@gmail.com";
$subject = "Resume";
$message = $_POST['msg'];
$to = "nevinthomas153@gmail.com";
$file = $path.$filename;
$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);
$header = "From: ".$from_name." <".$from_mail.">rn";
$header .= "Reply-To: ".$replyto."rn";
$header .= "MIME-Version: 1.0rn";
$header .= "Content-Type: multipart/mixed; boundary="".$uid.""rnrn";
$header .= "This is a multi-part message in MIME format.rn";
$header .= "--".$uid."rn";
$header .= "Content-type:text/html; charset=iso-8859-1rn";
$header .= "Content-Transfer-Encoding: 7bitrnrn";
$header .= $message."rnrn";
$header .= "--".$uid."rn";
$header .= "Content-Type: application/octet-stream; name="".$filename.""rn"; // use different content types here
$header .= "Content-Transfer-Encoding: base64rn";
$header .= "Content-Disposition: attachment; filename="".$filename.""rnrn";
$header .= $content."rnrn";
$header .= "--".$uid."--";
if (mail($mailto, $subject, "", $header)) {
echo "mail send ... OK"; // or use booleans here
} else {
echo "mail send ... ERROR!";
}
请帮助我
mail
() 函数并不完全知道可以创建最完美的邮件。垃圾邮件过滤器对邮件标题非常挑剔,自己正确构建它们并非易事。最好使用SMTP库来创建具有所有重要标头的邮件(如phpmailer)
还要确保您发送邮件的服务器具有良好的IP信誉和正确的邮件设置(HELO/反向DNS等)