简体   繁体   中英

Mail go to spam instead of inbox and some errors in header part of mail using PHP

i am trying for send mail using php.My mail go to spam and some other errors are also in mail.

My header code is

$header_mail="select content from mail_header where id='1'";
$header_mail2=mysql_query($header_mail);
$fet=mysql_fetch_array($header_mail2);

$content= htmlentities($fet['content']);

$Headers = "From:$content\r\n" . 
"Reply-To:$content\r\n" . 
"Content-type: text/html; charset=UTF-8 \r\n"; 
$Headers.= "MIME-version: 1.0\n";
$Headers.= "Content-type: text/html; charset= iso-8859-1\n";

data in $content is zamisoft<zamisoft.com> but i got the mail as with

from:    Zamisoft&lt

reply-to: Zamisoft&lt, zamisoft@gmail.com&gt

I got the these message in mail

"Be careful with this message. Many people marked similar messages as phishing scams, so this might contain unsafe content. Learn more "

Mail is going to spam and errors are in header section part of mail.

Any body help me for solve these issue?

The problem is simple that the PHP mail() function is not using a well configured SMTP Server .

Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.

Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.

https://github.com/PHPMailer/PHPMailer

remove the htmlentities() from $content= htmlentities($fet['content']); and then try!

Since you are already setting the Content Type and Character Encoding , the contents of the array $fet['content'] will be read properly by the browsers!

htmlentities() converts the html tags to htmlentities (eg. < to &lt; ) which is what you are facing!!

Try it and let us know if the problem persists

Remove the line "Content-type: text/html; charset=UTF-8 \\r\\n"; as you have defined the header in the last line of header.

Add $Headers .= 'X-Mailer: PHP/' . phpversion()."\\r\\n"; at the last line of your code.

It tells which version of php is being used!

Also the email address should be a valid one as well!!

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