I know that there are many similar questions on this site, but none of them helped me.
I have the following PHP code:
<?php
$to = "mymail@inbox.com";
$from = "no-reply@heygee.com";
$subject = "Confirm your registration!";
$message = "Please follow this link to confirm your registration: www.bit.ly/32106";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: HeyGee! <no-reply@heygee.com>" . "\r\n" .
"Reply-To: mymail@inbox.com" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$ok = @mail($to, $subject, $message, $headers, "-f " . $from);
?>
Let's say mymail@inbox.com
is my test e-mail. Whenever I send the mail to my address, I always receive the mail in my Spam folder. Why is that? Are there any corrections or tricks to be made to prevent the mail from arriving in Spam?
Thanks.
The reason why your mail is being sent to Spam folder is either because of the content of your email or that the receiving side is not able to verify if the email actually came from the stated domain in the from
address, i.e., if the sender (you) are authorized to send email on behalf of heygee.com
.
Content part is easy to correct. You need to avoid bad grammar, ambiguous links (e.g links which say google.com
but point to example.com
), etc. Your message should be well worded (exclude those words frequently found in spam mails), and preferably include an unsubscribe link
as well (if sent to a mailing list).
Now comes the second and difficult part. The domain that you are writing in your from
address should be the same domain from which you are executing this mail script or should be authorized by this domain's TXT records to send mail on its behalf. The simplest way to go about this would be (provided you have DNS
access to the sending domain name) to add a TXT SPF
record permitting the IP of the server your script resides on to send mail on its behalf.
Example SPF
record:
"v=spf1 ip6:1080::8:800:200C:417A/96 -all"
The above record means Allow any IPv6 address between 1080::8:800:0000:0000 and 1080::8:800:FFFF:FFFF.
Checkout: SPF (Wikipedia)
Also, you may have a look here http://www.openspf.org/
Now if you don't have DNS access, then simply change the domain name of the from
address to the domain name of the server and it should fix it.
Hope it helps.
This is not related to your programming by itself. Filtering e-mail as spam is done on the client side and there is nothing you can change about that (if it were, millions of spammers would be doing it)
The problem you have is that your e-mail looks like spam. Try to write a better e-mail, with a body longer than 1 line. I would also remove the exclamation mark from the subject; that's also something that makes it look like spam.
If your spam detection system gives you detailed information on why it was labeled as spam (SpamAssassin can do that depending on how it is configured), then use that information to fix the e-mail that you send.
来源:https://stackoverflow.com/questions/28795343/php-mail-is-being-sent-to-spam