How to avoid my mails sent from PHP mail() being marked as spam?
Asked Answered
P

2

6

I'm using the following to send registration e-mails:

$subject = 'subject is here';
$message_raw = 'e-mail text';

$message = base64_encode($message_raw);

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: base64' . "\r\n";
$headers .= 'From: papa.sk <[email protected]>' . "\r\n";

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

For some people the e-mails are put into the spam folder (in gmail too).

In /etc/postfix/main.cf I have this:

myorigin = /etc/mailname
smtpd_banner = papa1.vps.websupport.sk ESMTP

Not sure whether I should change the above.

Pretext answered 9/10, 2011 at 20:13 Comment(9)
Don't send spam. (Right?) Of course, I'm kidding. The most effective way is to have your users mark your emails as NOT being spam. There aren't many great solutions (thanks spammers).Stesha
I never sent any spam. It's a new server, new site. Less than 10 mails have gone out since it's been deployed. The server is dedicated to the site.Pretext
Base64 encoded messages have a high probability of being spam.Rickeyricki
You'll need to investigate all the ways in which your emails could be marked as spam; there are several, some of which you may not think, and others you (at times) have no control over.Stesha
@PaulTomblin So how do I send the mail? It's written in slovak, therefore it contains special characters like š č ú ä ô etc ...Pretext
did you check that your subject does not contain words like 'enlarge' or 'viagra'?Coligny
Use PHPMailer or SwiftMailer and send it via your Google Mail account.Troutman
You already marked it as UTF-8, so why not send it in UTF-8 instead of base64 encoding it?Rickeyricki
You're marking the mail as from @papa.sk. What does your mail server's IP reverse-lookup as? if it comes back as xyz.somehost.org, that's a major spam flag. Look at setting up domain keys/sender ID for your server.Thready
B
2

The php mail() function has nothing to-do with your emails being marked as spam.

That an email is being marked as spam happens on the other end. You can not influence the process much with mail() - as it's the other end.

There can be thousand of reasons why an email is being marked as spam, and as long as you don't know the concrete reason why your email is being marked as spam, you can do nothing against that.

There is a whole industry which makes a living of that btw.

Bonine answered 9/10, 2011 at 20:19 Comment(2)
If it were possible, major corporations would not plead with you when they send you an email to "mark this not as spam".Stesha
@RiMMER: I do not understand what you mean.Bonine
G
4

you may need a reverse dns record for your server.

many mail servers considers that mails sent from a host are spam if the hostname cannot be looked up. that is nslookup papa.sk should return an ip address, and nslookup <ip address> should return papa.sk.

Gilberte answered 9/10, 2011 at 20:19 Comment(4)
Can I set the hostname that is being reported back somehow on my server, or do I have to ask my hosting company to set it for me, outside of the server? I have a full root access to it ...Pretext
you first have to put it on your server (by configuring a dns server), but also to tell your hosting company that you need such a reverse dns. note that many hosting companies do not provide this service. one way to circumvent this problem is to send mail through the mail relay that your hosting company do surely provide.Gilberte
Where could I find a guide for the mail relay thing?Pretext
your hosting company should have given you a documentation with the name of their mail server, and the associated login/password. then you have to look in the PHP documentation how to configure the mail() function to use that server.Gilberte
B
2

The php mail() function has nothing to-do with your emails being marked as spam.

That an email is being marked as spam happens on the other end. You can not influence the process much with mail() - as it's the other end.

There can be thousand of reasons why an email is being marked as spam, and as long as you don't know the concrete reason why your email is being marked as spam, you can do nothing against that.

There is a whole industry which makes a living of that btw.

Bonine answered 9/10, 2011 at 20:19 Comment(2)
If it were possible, major corporations would not plead with you when they send you an email to "mark this not as spam".Stesha
@RiMMER: I do not understand what you mean.Bonine

© 2022 - 2024 — McMap. All rights reserved.