0

我正在使用 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.">\r\n";
        $header .= "Reply-To: ".$replyto."\r\n";
        $header .= "MIME-Version: 1.0\r\n";
        $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/html; 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=\"".$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";
        $header .= "--".$uid."--";
        if (mail($mailto, $subject, "", $header)) {
            echo "mail send ... OK"; // or use booleans here
        } else {
            echo "mail send ... ERROR!";
        }

请帮我

4

1 回答 1

0

并不完全知道 mail() 函数可以创建最完美的邮件。垃圾邮件过滤器对邮件标题非常挑剔,要自己正确构建它们并非易事。最好使用 smtp 库来创建带有所有重要标题的邮件消息(如 phpmailer )

还要确保您发送邮件的服务器具有良好的 IP 信誉和正确的邮件设置(HELO / 反向 DNS 等)

于 2013-11-05T06:43:46.463 回答