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 <register@papa.sk>' . "\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.

Richard Rodriguez
  • 6,863
  • 14
  • 53
  • 96
  • 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). – Jared Farrish Oct 09 '11 at 20:14
  • 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. – Richard Rodriguez Oct 09 '11 at 20:15
  • Base64 encoded messages have a high probability of being spam. – Paul Tomblin Oct 09 '11 at 20:16
  • 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. – Jared Farrish Oct 09 '11 at 20:17
  • @PaulTomblin So how do I send the mail? It's written in slovak, therefore it contains special characters like š č ú ä ô etc ... – Richard Rodriguez Oct 09 '11 at 20:17
  • 2
    did you check that your subject does not contain words like 'enlarge' or 'viagra'? – javagirl Oct 09 '11 at 20:19
  • Use PHPMailer or SwiftMailer and send it via your Google Mail account. – mario Oct 09 '11 at 20:20
  • 2
    You already marked it as UTF-8, so why not send it in UTF-8 instead of base64 encoding it? – Paul Tomblin Oct 09 '11 at 20:23
  • 1
    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. – Marc B Oct 09 '11 at 23:35

2 Answers2

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.

Adrien Plisson
  • 19,742
  • 4
  • 38
  • 71
  • 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 ... – Richard Rodriguez Oct 09 '11 at 20:25
  • 1
    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. – Adrien Plisson Oct 09 '11 at 20:29
  • Where could I find a guide for the mail relay thing? – Richard Rodriguez Oct 09 '11 at 20:34
  • 1
    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. – Adrien Plisson Oct 09 '11 at 20:39
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.

hakre
  • 178,314
  • 47
  • 389
  • 754