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".
Related
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.
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.
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..
Okay, I have searched on the internet for answers- sadly to no avail. I'm trying to send mail using the PHP mail() function so members can follow the link to register. It works for Gmail, Yahoo!, but not for Hotmail. Please help meh!!!
<?php
$headers .= 'To: <kenny.XXX#hotmail.com>' . "\r\n";
$headers .= 'From: <XXX#srv30.000webhost.com>' . "\r\n";
$headers .= 'Cc: XXX#srv30.000webhost.com' . "\r\n";
$headers .= 'Bcc: XXX#srv30.000webhost.com' . "\r\n";
$text="hello";
$text = str_replace("\n.", "\n..", $text);
mail('Kenny Worden:<kenny.XXX#hotmail.com>','Leos Realm account verification!',$text,$headers);
?>
If this helps anyone:
SMTP : localhost(srv30.000webhost.com)
SMTP PORT: 25
Your code seems to be good. My guess is that there is something wrong at your servers end, check mail delivery logs or have your server admin look at them for you. Could be a routing/dns issue.
edit:
i just tried that script on my server and it works well. immediately got email on my hotmail address.
You're missing the string "-f <from address>" as the fifth parameter.
The PHP Manual points out that you need to supply this so that the MTA will send the correct "From" address on the envelope. Setting it in the headers isn't enough. This sort of inanity is why I dis-recommend mail() and point people towards php-mailer or similar.
(The "envelope" refers to the conversation an MTA has with another MTA in order to deliver email.)
code likes fine,
anything you do that makes it look like spam will block it from hotmail
try creating spf records for your domain, and even signatures
check your mail server is not blacklisted, this can cause problems
http://www.mxtoolbox.com/
As #staticsan recommends php-mailer or also http://swiftmailer.org/ are other options you can use try that might help
in my website i've a PHP script that automatically mails to my customers a confirmation about the order.
My website's domain is registered to a company that hosts my website too.
I have a lot of problems to send e-mails using mail() function to some e-mails accounts ... a lot of my users contact me saying that they have never received my automatic e-mail! So this is a very big problem!
The accounts, that give me more problems, are comcast.net, uol.com, mchsi.com and others! I've contacted the support center of these e-mail service providers asking for removing my ip from the block list too.
The header of the e-mail looks like this:
$header = "Sender: $from_mail\n";
$header .= "From: Account <$from_mail>\n";
$header .= "Reply-To: Account <$from_mail >\n";
$header .= "Content-Type: multipart/mixed; boundary=$mixed_boundary\n";
$header .= "Mime-Version: 1.0\n";
$header .= "X-Mailer: PHP/".phpversion()."\n";
$body = "\n--$mixed_boundary\n";
.
.
.
.
$body .= "\n\n--$mixed_boundary--";
mail($to, $subject, $body, utf8_encode($header), "-f$from_mail");
There is something that I can try to avoid this problem?
Someone knows where can I look to know what is the IP address of the server used to deliver e-mails thought the PHP mail() function?
Thanks in advance for your replies!!!
Hi,
still today some e-mail provider service such as Comcast, continue to block my IPs addresses saying that my mail server sends spams ... I requested the removing from the blocklist, but their system continue block them! I don't know what else can I do ... I've followed your suggestions and the code look like this:
$md5 = md5(date('r', time()));
$mixed_boundary = "PHP-Mixed-$md5";
$alt_boundary = "PHP-Alt-$md5";
$header = "Sender: $from_mail\r\n";
$header .= "Errors-To: $from_mail\r\n";
$header .= "From: account <$from_mail>\r\n";
$header .= "Reply-To: $from_mail\r\n";
$header .= "Content-Type: multipart/mixed; boundary=$mixed_boundary\r\n";
$header .= "Mime-Version: 1.0\r\n";
$header .= "X-Mailer: PHP/".phpversion()."\r\n";
$body = "\n--$mixed_boundary\n";
$body .= "Content-Type: multipart/alternative; boundary=$alt_boundary\n";
.
.
.
.
$body .= "--$mixed_boundary\n";
$body .= "Content-Disposition: attachment filename=\"...\"\n";
$body .= "Content-Type: application/octet-stream; x-unix-mode=0644; name=\"...\"\n";
$body .= "Content-Transfer-Encoding: base64\n";
.
.
.
.
$body .= "\n\n--$mixed_boundary--";
mail($to, $subject, $body, utf8_encode($header), "-f$from_mail");
Suggestions?
Thanks again!
Let me explain the battle you are facing. Forget about the technical details for a minute.
There are hundreds of email providers out there. The big ones are Yahoo, Gmail, AOL, Hotmail, etc. If you are blocked on anyone of these services your business could be severely affected.
These email providers are extremely concerned about spam and in order to combat spam have gone to the extreme of blocking any messages that might be spam. You might never get spam complaints but if another business, on your shared hosting plan, gets spam complaints you will be effected. It doesn’t matter how you configure your application if you are on a suspected spam IP address your messages will be sent to the spam folder.
Even if you have your own server you will still have issues. Over time if you send emails some of the recipients will hit the spam button. This is a fact of life and there is nothing that you can do to prevent it.
The only solution is to outsource you email delivery. Companies like Aweber or iContact deal with email delivery issues for you. They have relationships with all major email providers and work hard to ensure that your messages get into the recipients inbox.
You no longer have to worry about contacting Yahoo or Gmail because someone hit the spam button. You can focus on more important things.
Your message headers are not valid according to RFC2822 Internet Message Format.
From 2.1 General Description:
Messages are divided into lines of characters. A line is a series of
characters that is delimited with the two characters carriage-return
and line-feed; that is, the carriage return (CR) character (ASCII
value 13) followed immediately by the line feed (LF) character (ASCII
value 10). (The carriage-return/line-feed pair is usually written in
this document as "CRLF".)
As I pointed out in my comments, the reason why your email may work with most mail servers anyway is that they may be liberal in what they accept. There may be some mail servers, however, that will discard your messages since they don't comply with RFC2822.
EDIT: Although the use of "\r\n" is advocated in the PHP documentation for the mail() function, there is some debate about whether that's really the right thing to do.
The mail() function will communicate with the local sendmail(8) command (or whatever is configured in sendmail_path), and the line endings may be processed differently depending on what mail transfer agent implementation is used. From what I understand, sendmail(8) should be OK with "\r\n", but qmail(7) for example will replace "\r\n" with "\r\r\n", which will probably break the message.
This all happens before the email is delivered to its final destination, so it may be easily tested whether the line endings are processed properly by sending one's self an email message constructed with "\r\n" and by verifying that all headers are present.
See also: RFC2822, PHP mail() function, sendmail(8), qmail(7)
You could send yourself an email and check the headers. That will give you an idea of the path an email might take, but there's really nothing preventing emails to those other domains from going through a different path.
In general those big ISP's have really heavy duty spam filters, so mailing to them from a shared host is going to be tough. If you can get your own IP address and send mail from there, it will probably help. Then you can set up SPF records. No guarantees, but that will definitely elevate you out of the pit of commercial spammers a bit.
You could also do some digging with link text and some of the other anti-spam services and see if you're doing anything else wrong.
Asking customers to add your from address to their spam whitelist probably wouldn't hurt either.
I've found that setting Return-Path, Sender, and Errors-To headers help in some cases.
Use PHPMailer (http://phpmailer.worxware.com/) for building the email-messages. Maybe it's not the IP, but something else. There are a lot of things, where spamfilters react allergic (like missing Message-ID etc.). Plus with PHPMailer you have the opportunity to send your mails via mail() or if it dont't work due to shared-hosting-problems via SMTP over an other host (like Gmail).
I've noticed that with my Linux hosting server, I have to replace all occurrences of CRLF with LF in both the extra headers and the mixed/alternative headers. About that the PHP documentation says:
"If messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822."
I've tried to send a mail (only with "\n") to my personal account and I've looked for "\r" and "\n" in the raw message ... each line is ended by a CR and started with a "\n"!
QUESTION: As the PHP mail() documentation says, I use the function wordwrap() to cut the line length to 70 characters.
There is a workaround to let the mail client to display the message with its original formatting and not as a column where each line isn't longer than 70 chars?
ANSWER [SOLUTION]: I have solved setting up quoted-printable as Content-Transfer-Encoding:
$body .= "Content-Transfer-Encoding: quoted-printable\n";
$body .= "Content-Type: text/plain;\n\tcharset=utf-8;\n\tformat=flowed;\n\tdelsp=yes\n";
$body .= "\n" . quoted_printable_encode($message);
The quoted_printable_encode() function is available only with PHP 5.3, the implementation is suitable in the documentation page.