My website emails are going to Spam in gmail [duplicate] - php

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.

Related

PHP Mail is Being Sent to Spam [duplicate]

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.

Mail ends up in junk folder - PHP contact form [duplicate]

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..

PHP mail() - marked as spam [duplicate]

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).

PHP mail may be filtered out by spam?

I am creating a small company, and would like to send out emails to my clients once they have signed up for my service to activate their accounts. I am currently using PHP's mail() function, however I am worried that my emails are being filtered out by spam filters. Is there a better way to go about this?
$email = 'XZY Client Email address # somedomain.com';
$emailSubject = "Welcome to XYZ Service!";
$to = $email;
$subject .= "".$emailSubject."";
$headers .= "From: no-reply#XYZService.com\r\n" .
"X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= "Welcome to XYZ Service! \n Activate your account by clicking the following link: link...";
mail($to, $subject, $message, $headers);
Is there a way to authenticate these emails so that my clients know that they are from my actual service? Thank you in advance!
You can try to get your mail server white listed by some of the major postmasters (AOL, Gmail, Hotmail, etc.).
I am not sure if this is what you want, but you can setup a mail server to handle all your emails.
Try using that mail server for sending emails and see if they are still filtered or not.
BTW, setting up a mail server on *nix systems is free and worth giving a try.
I have a simple arcade site that people from my highschool use and for quite a while I've been using the method that you showed. I didn't look at my code to verify that they're identical, but they look fairly close and mine works with gmail and all other big name services I've ran into!
Just remember that some hosting companies limit the amount of PHP mail that can be sent per minute. Mine only allows 9 per minute, I know I've gotten suspended a few times on accident while running test mail sends, haha.

Safely send many emails in PHP

I'm building a website in PHP that allows users to send invitation emails. They are allowed to send more than one at once.
I'm told that using PHP's mail() function is a bad choice because it can easily be marked as spam. Is there some way that I can set up this script so that the emails are not marked as spam?
I've done quite a lot of reading and from what I've read today it seems like a few factors can influence whether mail is marked as spam including: the words used in the emails; the domain that the emails say they are sent from compared to where they actually originate; formatting of headers; and the frequency of emails sent.
The email addresses that we use are with Gmail Apps. So, if the emails I send don't "look" spammy, I send them from Gmail, and I can limit the frequency of the emails sent (maybe 10 every 10 minutes) then I should be able to do this without a problem right?
EDIT
This is not for a newsletter. Do I even have to worry about being marked as spam for invitation emails?
while your conclusion is correct, your reasoning is not quite right. php's mail function will not cause your emails to be marked as spam, because it sends the same emails as anything else would.
the problem with php's mail function is that it is very low level, and so if you do not know how to use it properly, and leave email injection vulnerabilities, people could use your site to send spam messages through it, and in turn this could get your server blacklisted as a source of spam by isps. as long as you strip \n and \r from your extra header fields (From:, etc), you should be safe.
Another issue is that you have to add your own valid headers to your emails.
Yet another issue is that it would connect and disconnect from your smtp server for each time you call mail(), although I think there is a way you can send multiple emails using one call to mail. this would be complicated though since it would probably involve looking through rfc282 and figuring out how to do it.
at first you need an valid mx.record for your domain...
if you use the mail function you should send valid headers like these:
function send_mail($from = FALSE,$to = FALSE, $msg = FALSE, $subject = FALSE, $html= TRUE){
if($from && $to && $msg && $subject){
if ($html){
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
}
$header .= 'From: '.$from. "\r\n";
$header .= 'Reply-To: '.$from. "\r\n";
$header .= 'X-Mailer: PHP/' . phpversion();
return mail ($to,$subject,$msg,$header);
}
return "fail";
}
you need to use a SMTP server and after that connect using any php library for php. Here you have some useful libraries and some examples as well
http://phpmailer.worxware.com/
http://swiftmailer.org/
http://framework.zend.com/manual/en/zend.mail.html

Categories