1

I have set up a contact form, with basic fields. The form is sent to the site owner and a message sent to the customer submitting the form. The function works but allways send the message to the junk folder. Is there something wrong with my headers or is it just hotmails junk settings.

$headers = "MIME-Version: 1.0rn"; 
$headers .= "Content-type: text/html; charset=iso-8859-1rn"; 
$headers  .= "From: contact@mysite.com\r\n"; 
mail($to, $subject, $message, $headers)or die("mail error");

The message's are HTML emails, just a nicer way of displaying the message. Also in my email account instead of displaying my from varable it says ,' CGI Mailer' -- confusing.

UPDATE - no longer works at all

//mail customer
$from = 'donotreply@mysite.co.uk';
$subject = 'Your message has been recieved.';

$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers .= 'From: My Site <'.$from.'>' . "\r\n";

$msg = '
<html>
<head>
<link href="http://linktocss/.../etc" rel="stylesheet" type="text/css" />
</head>
<body>
formatted message...
</body>
</html>
';
mail($email, $subject, $msg, $headers)or die("mail error");
Paul Ledger
  • 1,125
  • 4
  • 21
  • 46
  • Most likely because of the way your have `rn` bunched up like that. Read the manual http://php.net/mail - Your headers are invalid. – Funk Forty Niner Jan 27 '14 at 14:18
  • there is no right answer for this question. you need good understanding of Junk/Spam email rules and a little bit of luck as far as I am concern. Just make sure that your email is well formated, that your domain for mail sending has DKIM, PTR and reverse dns record. That you have real unscribe link in your emails, that your server is not on some rbl blacklist. That being said, your question is just to big to answer. – pregmatch Jan 27 '14 at 14:53

2 Answers2

2

Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.

Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.

2

Edit

This worked for me, and did not end up in SPAM/Junk, but in my Inbox.

<?php
//mail customer
$from = 'donotreply@mysite.co.uk';
$to = "email@example.com";
$subject = 'Your message has been received.';

$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers .= "From: The Sending Name <$from>\r\n";

$msg = '
<html>
<head>
<link href="http://linktocss/.../etc" rel="stylesheet" type="text/css" />

</head>
<body>
formatted message...
</body>
</html>
';
mail($to, $subject, $msg, $headers)or die("mail error");

?>

Footnotes: I noticed that you are using an external stylesheet. Many Email services such as Google will not render those. It's best to use inline styling to achieve better/desired results.


Original answer

The (most likely) reason (as per your posted code) why your mail ends up in SPAM is that your headers are invalid.

You have rn bunched up together, instead of using \r\n

Use this instead:

$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers  .= "From: contact@mysite.com\r\n"; 
mail($to, $subject, $message, $headers)or die("mail error");

Or better yet, use: As taken from the PHP website's mail() function

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers  .= "From: contact@mysite.com\r\n"; 
mail($to, $subject, $message, $headers)or die("mail error");
Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141