Why is this email spamming?


I am trying to send an email, but it keeps going into the “Junk” folder, now i think this is because of the wording in the email that is being sent. This only happens with MS Outlook, when i use hotmail or another email it works fine and goes into the inbox.

This is my code:

        $msg = "New review submitted about company: ".PHP_EOL;
        $to = "****@********.com";
        $from = "dontreply@thelinenhire.co.uk";
        $subject = "linen";
        //end of message
        $headers  = "From: $from\\r\
        $headers .= "MIME-Version: 1.0\\r\
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\\r\

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

Any ideas why this is happening?


AFAIK the last header should have an extra newline - i.e. a blank line - to signal the email client that the header has ended and the message body is coming up next.

Technically, yes, but the mail() function takes care of that, you don’t have to do that yourself :slight_smile:

I was having the same issue a long time ago and I believe I fixed it by rearranging the header information.

Try rearrange your header info in this way:

$headers  = 'MIME-Version: 1.0' . "\
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\
$headers .= 'To: ex <ex@customer.com>' . "\

Also remove the \r as some servers have problems with it.

Furthermore, I was having issues where some email clients were not able to make the hyperlinks in the message clickable. By rearranging the header it fixed it for me.

Swiftmailer (http://swiftmailer.org/) is another nice library you can use. I find it a little easier to read and use than PHPMailer.

I agree with tangledman, phpmailer is really great, and not hard to use AT all!


This seems like a long winded process? Is there anything that i can alter in my code?

Thanks again

You might want to familiarize yourself with how spam filters think.
There is no general way to say “do this in that and your mail won’t be seen as spam”. If there were we’d all get a lot more spam :slight_smile:

Try using phpmailerhttp://phpmailer.worxware.com/

I had the same problem and this worked for me.