简体   繁体   中英

mail gt marked as spam by gmail, any solutions?

i am using php code to send a mail with an attachment in my web application. all are working fine expect gmail marked it as spam. my code is look like below.

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!";
        }

Please help me

the mail() function isn't exactly known to create the most perfect mails . Spam filters are very picky about mail headers, it's no easy task to build them all correctly yourself. better use a smtp library that creates the mail messages with all important headers (like phpmailer )

also make sure the server you send the mails from has a good IP reputation and correct mail setup (HELO / reverse DNS etc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM