Prevent sent emails treated as junk mails using ph

2019-01-03 03:10发布

I wrote a PHP script to send emails.

My script is like this:

$headers =  'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: abc@yahoo.com' . "\r\n";

// Email Variables
$toUser  = "someone@yahoo.com"; // recipient
$subject = "testing"; // subject
$body    = "<html><body><p>
             Example of including an image via html \<img\> tag:
             <br>
             <img src='../images/profile.jpg'>
             <br>
             My new picture
             <br></p></body></html>"; // content

if (mail($toUser,$subject,$body,$headers)) {
    echo "sent";
} else {
    echo "failed";
}

Well, of course I use a valid email address for sender and receiver. I did receive the email, but it goes to junk mail. So I went for google research. Is it because of my "header" script problem? If it isn't, then what could cause my script to send a junk mail? Any solution?

14条回答
女痞
2楼-- · 2019-01-03 03:31
  1. On your server try to sort your SPF (Sender Policy Framework, Google for SPF record) record out.
  2. Make sure you send your e-mails from an existing account on your server/domain.
  3. Make sure you have the reply-to address in your header.

These are the basic things you can try.

查看更多
该账号已被封号
3楼-- · 2019-01-03 03:31

Remove the Content-type: text/html and add $headers .= "X-Priority: 2\nX-MSmail-Priority: high"; to get rid of Spam. This method has been tried and tested.

查看更多
小情绪 Triste *
4楼-- · 2019-01-03 03:33

the problem is, the server you're sending the mail from is not a yahoo server. most spam filters check if they match, otherwise it would (and is - or was) possible to easily fake the sender. ever wondered why you get spam from bill.gates AT microsoft.com or your own mail address?

查看更多
Evening l夕情丶
5楼-- · 2019-01-03 03:34

1. Check mail content

As others have hinted it is probably marked as spam because your mail looks like spam.

I am not sure if you the script that you have posted is the actual one that you are testing.

If it has the actual mail body & headers, then running this message through a standard installation of SpamAssassin gives it a spam score of 4.9

X-Spam-Status: No, score=4.9 required=5.0 tests=BAYES_50,HTML_IMAGE_ONLY_04,
        HTML_MESSAGE,MIME_HTML_ONLY,NO_DNS_FOR_FROM,NO_RELAYS autolearn=no
        version=3.2.5

Since the email body has only HTML it has a greater chance of being handled with suspect by most anti-spam solutions.

2. Mail server's IP

Another aspect worth checking will be the IP address of your mail server. Any mail originating from dynamic IP addresses will potentially be considered as SPAM.

3. Blocklists

Also check if your IP address is listed in one of the block lists. To start with please check your IP address with http://www.spamhaus.org/lookup.lasso.

查看更多
孤傲高冷的网名
6楼-- · 2019-01-03 03:35
                   **This Works Perfectly fine for me**     
                        $to="reciever@reciever.com";
                        $subject="This is Your Message";
                        $from = 'Sender <noreply@sender.com>';
                        $body='Hi '.$name.', <br/><br>Now You can See Yor main in inbox';
                        $headers = "From: " .($from) . "\r\n";
                        $headers .= "Reply-To: ".($from) . "\r\n";
                        $headers .= "Return-Path: ".($from) . "\r\n";;
                        $headers .= "MIME-Version: 1.0\r\n";
                        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
                        $headers .= "X-Priority: 3\r\n";
                        $headers .= "X-Mailer: PHP". phpversion() ."\r\n";
                        mail($to,$subject,$body,$headers);
查看更多
姐就是有狂的资本
7楼-- · 2019-01-03 03:37

Please try this:

$headers ="From:<$from>\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-type: text/html; charset=iso 8859-1";

mail($to,$subject,$body,$headers,"-f$from");
查看更多
登录 后发表回答