Question

Im using PHP's mail() function to send some emails. But all my mails land automaticly in the trash box. Is there a way of preventing this? If so, where should i read to learn more about it.

Would you recommend me using PHPmailer?

Best of regards, Alexander

Was it helpful?

Solution

I suppose you mean thrash box at the receiver's end. So basically the receiving email server is regarding it as spam. This can happen if:

1) The IP you are sending from is already blacklisted for spamming (happens often in shared hosting)

2) The IP and domain are relatively new and unknown.

(Note that many times, newsletters from well established sites also end up in spam).

If its your dedicated IP, then setting RDNS for the IP, to match the domain name will very likely solve the issue. Another usual practice is to alert the receiver (if she is subscribing on your website) to check their thrash/spam folder and whitelist your email address in their mail account.

regards,

JP

OTHER TIPS

Not to boast, but I am a mail server engineer. Spam filters look for a number of "problems" with email and add "points" for each little problem. If enough of those problems add up, the email could be (any of): refused during SMTP, routed to Spam folder, routed to Inbox, but tagged "SPAM" blackholed (mysteriously lost).

To avoid this problem, you want to fix SEVERAL problems, and this will reduce your spam score or spam policy conflict. You want to go out of your way and learn a little bit about "email best practices" actually, if you want best results.

1 issue is: do not send email to a recipient, from a PHP script on a webserver. Not directly to the recipient, anyways.

Anti-spam software learned long ago to distrust web-based email, because of all the insecure installations of formmail.pl, etc.

The CORRECT way to send email from a webserver is to send the email through a valid mailbox on a valid mailserver. So if your website has email hosting, create a mailbox called for example 'website-notification@websitedomain.com'. Call it what you like. Now you want your PHP script to send the email -through- that address, using Authenticated SMTP. I'll leave the process of learning how to use Authenticated SMTP from PHP as a learning exercise for you (there are many tutorials online).

Once you send emails through your valid SMTP server, maybe your email is delivered better.. but don't stop there. You could still have the same problem at some other email delivery domain...

2) As someone else noted, Be sure you are not missing To: From: Subject: and Date:. Date must be in the standard date format for email or some spam filters will flagg it. If you are missing any header you will get tagged for spam points.

3) Your FROM address must be a VALID mailbox. Do not send email using "From: noreply@yourdomain.com". The from address must exist because some anti-spam software will do a "Sender Verify" to test if the From address is bogus or fake.

On your mailserver, create noreply@. No one says you actually have to check that mailbox... you could have a rule which autodeletes all mail at the unmonitored address. The key point is, if other mailservers get a '550 No Such User' when they connect to your MX and test that mailbox, then your email could be flagged as spam.

4) If your domain DNS has an SPF record, be 100% sure it lists every IP that might send email for your domain. If unsure, do not use SPF records because a bad SPF record will hurt delivery rates.

5) Don't use "Domain Registration Privacy" or "Domain Proxy" services which hide your contact information from your WHOIS. Any legitimate sender of email does not need to hide the domain's contact information. Spam filters will check this.

6) Know the IP address of your mailserver, and regularly check that it is not "blacklisted" at SpamCop, SpamHaus, or the Barracuda spam blacklists. Google for more.

Hopefully my answer helps you, and conveys there is no simple single answer to it all. These days if you want to send email, you have to be aware of these issues.

JP's answer is partly correct but it also could be your header's in the email i know from experience this sends stuff to the spam folder try the following;

set the emails to your domain something like no-reply or a valid reply.

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

This probably has something to do with your mail client and spam settings configuration. Try opening account on gmail.com and sending email there, if it's OK you know it is your mail server/client problem. If it's not, post your PHP code and full email headers of the email you've got.

This happens because many a times, headers are missing / if its a well known email server domain key signature is not present, or something like that. If you already have a separate email server, you should check out if you can use the PHP Pear Mail package to send email using your email server, rather than directly via mail function. That's what I find convenient, as its much more flexible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top