This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 7 years ago.
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.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I'm using a basic script on a 1&1 hosted server:
$recipient = "email#domain.com";
$sender_name = $_POST['name'];
$sender_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type:text/html; charset=UTF-8"."\r\n";
$headers .= "From: {$sender_name} <{$sender_email}>"."\r\n";
$headers .= "Reply-to: {$sender_name} <{$sender_email}>"."\r\n";
mail($recipient, $subject, $message, $headers);
..but for some reason am not receiving any emails, nor any errors as per PHP mail() function not sending email instructs.
I thought this may be a server issue but 1&1 states that it is fully supported. I've also sent emails from this server/hosting before using just a recipient, subject and body and so I'm rather unsure as to why it is not working now!
UPDATE
Sending without headers, i.e.:
mail($recipient, $subject, $message);
..does work, so it would appear to be an issue with using the headers?
There may be many reasons, for example you should study what SPF is.
The $sender_email can't be any address, for example you can't put a gmail address and send emails claiming to be that sender, without any authentication, you aren't allowed to send email on behalf on that address, because I could for example send emails putting your address in the from, pretenting to be you when I'm not (I tried to use simple words)
You should use in the From something ending in #yourdomain.com, and set up SPF to allow your server's IP to send emails for that domain. OR otherwise send emails through SMTP (with PHPmailer, for example, it's very easy)
Errors in header does affect the mail delivery. if you send email with wrong headers, for example, let's say the email of the user is user#email.com and his name is "user user", and you send the email to user#email.com it might cause the email to go in spam or not accepted at all if it doesn't match on server.
Gmail, for one, has a name associated with every email id. if you put a wrong name with the email, there's a chance the email might not show up in inbox or sometimes even spams.
"But in the link I attached the example given uses a 'from' header set by a form input?"
if you want your users to be able to send email to you, best idea would be to use your own email address as the sender email. E.g. if your website is at website.com, configure an email like "contact#website.com" and configure your script to use this as From header, you can send it to your own email at the same domain(website.com) or any other email which you authorize. You can add the users's actual details in the mail. that'll ensure the successful delivery of the email always.
This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 7 years ago.
I have a web site that provides daily real estate updates. Users register, and we send them an email every day. However, Gmail is marking all of our emails as spam. What should we be looking out for?
Spam emails are based on Server, domain and blacklist history.
This is controlled by the Service Provider there is not a lot you can do to be honest.
The best thing is is to add the sender email to your safe list i.e. no-reply#example.com
Due to the simplicity of PHP, it is very easy to send a mail through
mail(), however there is 99% of chances that you are doing it wrong.
You need to follow the right guidelines to use mail(). My recommendation is use a third party mail service like Mandrill
If you still choose to go ahead with php mail(), please follow the below guidelines, which will help you to certain extend.
Set the right Headers:
$headers .= 'From: YourLogoName info#domain.com' . "\r\n" ;
$headers .= 'Reply-To: '. $to . "\r\n" ;
$headers .='X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$to = to#hello.com;
$subject = subject ;
$body = "<div> Email body goes here.. </div>";
mail($to, $subject, $body,$headers);
Message Sender Domain and Server Domain Should Match
Spammers are notorious for sending emails from one server and trying to make the recipient believe that it came from somewhere else. So if you are sending an email from sender#yourdomain.com, it is a good idea the the script reside on example.com.
The Server is not Blacklisted
When a server is blacklisted, it means that that server has identified as one that has been sending a lot of spam. This results in recipient mail servers rejecting or filtering any mail that is received from that server.
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?
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");
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.
When I've once had a similar problem I looked at the headers and found out that my host uses SpamAssassin. So I googled for 'SpamAssassin score' and found a multitude of information on how to incorrectly (and thus correctly) form an email.
For example: SpamAssassin score list
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.
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!
**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);
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.
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)
On your server try to sort your SPF (Sender Policy Framework, Google for SPF record) record out.
Make sure you send your e-mails from an existing account on your server/domain.
Make sure you have the reply-to address in your header.
These are the basic things you can try.
if your website domain is mydomain.com then in From headers make sure to use someone#mydomain.com
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.
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?
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;
You can try the mail class and test file that I have created here. I have tested the files and can send emails to my hotmail and gmail under a different mail name. The main reason why the emails are mark as junk is because the structure (both header and message) is not correctly done. In most cases, it is the line feed that is causing the problem.
I can use it to send mail with attachments to Gmail. However, the attachments dont work for hotmail. Hope this helps =)
You can check the files here..
This question already has answers here:
Gmail and Hotmail marked as spam
(5 answers)
Closed 8 years ago.
My emails that are send by mail() are getting directly into the spam box, tested with GMAIL and HOTMAIL.
So:
I have dedicated server
My server ip is not listed on any blacklists
This is my code:
function send_email($recipient, $sender, $subject, $email_body){
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$sender;
mail($recipient,$subject,$email_body,$headers);
}
$from = 'info#domain.com';
$subject = 'subject';
$email_body = '<h1 style="text-align:center;">Title</h1><p>Message</p>';
send_email($userbday['email'], $from, $subject, $email_body);
Any thoughts?
Try to setup an SPF record for your domain.
Also
Email is serious business.
Try transactional email service providers
It may be that your email looks exactly as spam. It sometimes happens...
All my applications sends email - depending on how the client prepare the email templates - some are treated as spam almost instantly, some not.
Setting SPF Record can help, but also check (and use) some blacklist emails for your own good - like people who dont want to receive your emila should never be bothered again as they can trigger your server to be in the black lists (for example spamcop).
My website sends activation mails to new members using the php mail() function. I manage my email accounts using the google mail service (aspmx.googlemail.com). But unfortunately, Hotmail users receive the activation email in their unwanted folder.
I did some research and found out about SPF records (I can not use keys since I have limited control over my webserver). So how do I configure my SPF record?
I now have:
v=spf1 a mx a:mywebsite.net include:aspmx.googlemail.com ~all
Would this be what I need?
EDIT:
I now used PHPMailer to connect to the google SMTP server. Hotmail no longer marks them as unwanted this way. (http://sourceforge.net/projects/phpmailer/)
PHP's mail() is probably not using smtp to send your emails. I would consider adding the appropriate headers and using a spam scorer to help your chances, or you could try and use smtp through google's mailservers (although I bet that is unlikely).
Here is a spam scorer:
http://www.contactology.com/check_mqs.php
Here is an example of some email headers, be sure to set your From header as its default probably isn't good for spam filters:
$headers = "From: My site<noreply#my_site.com>\r\n";
$headers .= "Reply-To: info#my_site.com\r\n";
$headers .= "Return-Path: info#my_site.com\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($recipient, $subject, $message, $headers);
Inorder to utilize that SPF record you need to add it to your DNS Zone file.
Go to wherever you have your DNS registered and add a couple of TXT records.
They should look something like:
mywebsite.net. IN TXT "v=spf1 a mx a:mywebsite.net include:aspmx.googlemail.com ~all
"
mailserver.mywebsite.net. IN TXT "v=spf1 a mx a:mywebsite.net include:aspmx.googlemail.com ~all
"
There is a ton of great info over at http://www.openspf.org/
This will not guarantee that your message will get through the spam filters, but it will help.
The other thing todo is get "whitelisted" with the Hotmail team. It has been a while, but you essentially register your machine with a contact. This allows them a person to complain to directly when questionable material comes from your site. They tend to let more of your mail through after you get yourself "whitelisted".