-3

I'm using the mail() to send a simple email but from some reason everything I try it goes straight to spam, am I missing something here?

<?php
    $to = "toemail@example.com";
    $subject = "your subject";
    $body = "<p>Your Body</p>";
    $headers  = "From: Sender Name <from@example.com>" . "\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    mail($to, $subject, $body, $headers);
?>
Matt Hutch
  • 433
  • 1
  • 5
  • 17
  • Check this post, might be useful: https://stackoverflow.com/questions/5935087/how-do-i-prevent-mails-sent-through-php-mail-from-going-to-spam – squancy Jul 10 '18 at 13:21
  • There's a lot that can trigger a message going into spam. Anything from the IP it's coming from to the content of the email. You'll have to do a lot of testing and evaluating to find out why it's being sent to spam. – aynber Jul 10 '18 at 13:22
  • spam has a lot of rules, things like setting up your server to only said X emails per Y seconds, making sure the sender is verified, the server IP has reverse DNS and isn't on any blacklists can help, it's hard to code something that will 100% avoid spam because ultimately it's down to the email recipients rules. Best thing to do is make sure your mail server is 100% golden (even then it'll end up in someone's spam) – treyBake Jul 10 '18 at 13:24

1 Answers1

0

You need an additional 'Reply-to' Header to ensure that the sender e-mail address is the same as the reply-to mail address. This should solve your problem.

e.g $headers = "From: $from\r\nReply-to: $email";

Also make sure that your headers are seperated by \r\n

Lukas
  • 768
  • 5
  • 22