0

I use a simple mail function for a contact form in my website.

$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$text = stripslashes($_POST['message']);

$message = '<html><body>'.nl2br($text)."</body></html>";
$mail = mail("info@domain.com", "Contact Form", $message,
     "From: ".$name." <".$email.">\r\n"
    ."Reply-To: ".$email."\r\n"
    ."X-Mailer: PHP/" . phpversion()
    ."MIME-Version: 1.0\r\n"
    ."Content-Type: text/html; charset=utf-8");

The email is send BUT it is always detected as Spam which is not good. Probably because the "FROM" is the email given by the visitor in the form.

How to solve this?

Benmay
  • 347
  • 1
  • 15

2 Answers2

1

Don't use the user's email address as the From header. It will give you inconsistent results with spam filters and in your case it introduces a header injection vulnerability. Instead use a valid static mailbox (that actually exists - preferably on the same domain as you're sending from).

You missed the \r\n suffix on some of your headers, namely X-Mailer and Content-type.

I would suggest checking your server's IP address, it may be blacklisted or listed as spam which will cause some spam filters to automatically reject or dump everything in the junk folder. This can be the case on shared hosts, even if you've never sent spammy mail from your own package, other hosting accounts on the server may have.

MrCode
  • 63,975
  • 10
  • 90
  • 112
0

Check this link to a post on StackOverflow: https://stackoverflow.com/a/2573286/1983368 Spam is mostly detected from the receiving end.

Community
  • 1
  • 1
drumkruk
  • 1,046
  • 9
  • 12