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:38

Use mxtoolbox.com to check the servers IP to be blacklisted or not. As well this website can help you with a couple of email related checks.

Of course there are a long list of checks running inside spam filters. As already suggested, check the email headers for details about the spam filters rating of the spam email.

Hope that helps!

查看更多
仙女界的扛把子
3楼-- · 2019-01-03 03:41

As schnalle said, one problem surely is that the smtp server that you use to send the email and the one thet you specify as From, is different.. the from's domain whould be the same that the server youre running on.

So, you can use the yahoo server to send the email (check if they allow the smtp remote connection, but i guess they do) connecting by smtp, and this will solve 1 problem.

Another one is the html contents without the alternative plain text contents, but, this one is less important.

I suggest you phpMailer, free and open-source php class to send email, easly to use (i use it event o send mail through gmail server)

查看更多
萌系小妹纸
4楼-- · 2019-01-03 03:44

Perhaps the problem is that yahoo uses domainkeys verification, which will likely fail for your application given that the mail is not actually coming from yahoo's servers.

查看更多
不美不萌又怎样
5楼-- · 2019-01-03 03:46

if your website domain is mydomain.com then in From headers make sure to use someone@mydomain.com

查看更多
孤傲高冷的网名
6楼-- · 2019-01-03 03:50

You've got two solutions:

  • use Yahoo's SMTP using abc@yahoo.com credentials to send mail from abc@yahoo.com;
  • use other from, with your own domain;
查看更多
ゆ 、 Hurt°
7楼-- · 2019-01-03 03:52

I was having the same problem:

The problem is that when you specify content-type before the "From:" part , the mail comes as a spam.

But if you specify "From:" before the content part it comes as a normal mail and makes you smile and curious.

查看更多
登录 后发表回答