Reputation: 6620
I've been doing a lot of reading up on this yet still can't find a solution. I'm building a site that sends a voucher by email to it's users once they've submitted a form. The problem I'm having is that the mail sent by the script is being screened by spam filters as being spam, yet it isn't as it's user submitted. This is the script I'm using:
<?php
error_reporting(0);
include("/home/users/web/b2243/moo.wheree/inc/event.inc");
include("/home/users/web/b2243/moo.wheree/inc/ad.inc");
$boundary = md5(time()) . "-2";
$eol = "\r\n";
$subject = "Tonights wheree voucher - $offer";
$fromaddress = "[email protected]";
$fromname = "wheree";
$headers = '';
$headers .= "Message-ID: <".time()."-".$fromaddress.">" . $eol;
$headers .= "Date: ".date('r'). $eol;
$headers .= "From: ".$fromname. "<".$fromaddress.">" . $eol;
$headers .= "Reply-To: ".$fromname. "<".$fromaddress.">" . $eol;
$headers .= "Return-Path: ".$fromname."<".$fromaddress.">" . $eol;
$headers .= "X-Mailer: PHP v" .phpversion(). $eol;
$headers .= 'MIME-Version: 1.0' . $eol;
$headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\"" . $eol . $eol;
$headers .= "This is a MIME-formatted message.". $eol . $eol;
$msg = '';
//text
$msg .= "--" . $boundary . $eol;
$msg .= "Content-Type: text/plain; charset=gb2312" . $eol;
$msg .= "Content-Transfer-Encoding: 8bit" . $eol;
$msg .= "Content-Disposition: INLINE" . $eol;
$msg .= "Content-Description: INLINE Description;" . $eol;
$msg .= strip_tags(str_replace("<br>", "\n", $rBody));
$msg .= $eol . $eol;
//html
$msg .= "--" . $boundary . $eol;
$msg .= "Content-Type: text/html; charset=utf-8;" . $eol;
$msg .= "Content-Transfer-Encoding: 8bit" . $eol;
$msg .= "Content-Disposition: INLINE" . $eol;
$msg .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" . $eol;
$msg .= 'Message Contents' . $eol;
$msg .= $eol . $eol;
$mail_sent = mail($email, $subject, $msg, $headers, "-f [email protected]");
// Check if Mail is sent
if ($mail_sent)
include("/home/users/web/b2243/moo.wheree/inc/sent.php");
else {
echo "<br> Message not sent, <a href="/">have another go</a>.<br>";
}
?>
The site is hosted on a shared hosting plan, could this be the problem? I've also heard about reverse DNS? Thanks in advance for your help.
Upvotes: 1
Views: 766
Reputation: 1074138
There are a lot of things this could be. Shared hosting could well be an issue, yes; check your server's IP on blacklist lookup tools such as http://www.mxtoolbox.com/blacklists.aspx. (And that's not just relevant to shared hosting, can happen with dedicated hosting as well — of 15-20 IPs I've been assigned with a new dedicated server over the years, at least 2 were already on blacklists. It's now the first thing I check when I get a new server.) It may help to set up SPF on your domain to explicitly list that IP as being a valid sender (whether the receiving mail server and client check or trust SPF is down to the receiving mail server and client, but it's something; it's unlikely to override an active blacklist record, though).
These days, running a mail server is a pretty big pain in the rear. I long ago opted to spend a tiny amount of money per year to outsource it (in my case, with Runbox). My code sends through their SMTP server rather than one I administer myself. In my particular case, I only send through them (I don't do any automated processing on received email, so I just have them go to Google Apps) but you can both send and receive with all the usual protocols. It's worked a treat for me, reducing the hassle factor tremendously. There are lots of other companies that will do the mail services for you as well, I'm not writing a commercial for this specific one, just for the concept.
Upvotes: 1
Reputation: 34837
If you're sending from a shared hosting account there are two important things you should know.
The best you can do is let your users/members know that they should whitelist your domain on their mail servers/clients to improve the chance of delivery. If that's not good enough, you should seriously consider some dedicated hosting solutions like a VPS, dedicated server or even your own PI space.
Upvotes: 2