title: Receiving Spam from my Form Using PHPMailer
body: <p>I am coming to stackoverflow for this because everything I search pretty much talks about email from a form using PHPMailer going to a users spam box. But, I need info on receiving spam from the form itself. I use it on a small, very light traffic real estate agents website. She gets spam from time to time and I don't know how to resolve it. PHPMailer seems to be the go to tool for sending email with PHP, so I figure spam/security is pretty well covered. I must be doing something wrong.... I am using class.phpmailer.php of course, and here is my code:</p>
  
  <pre><code>if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = trim($_POST["name"]);
    $email = trim($_POST["email"]);
    $phone = trim($_POST["phone"]);
    $message = trim($_POST["message"]);
  
  
  if ($name == "" OR $email == "" OR $phone == "" OR $message == "") {
      echo "You must specify a value for name, email address, phone, and message.";
      exit;
  }
  
  foreach( $_POST as $value ){
      if( stripos($value,'Content-Type:') !== FALSE ){
          echo "There was a problem with the information you entered.";    
          exit;
      }
  }
  
  if ($_POST["address"] != "") {
      echo "Your form submission has an error.";
      exit;
  }
  
  require_once("phpmailer/class.phpmailer.php");
  $mail = new PHPMailer();
  
  if (!$mail-&gt;ValidateAddress($email)){
      echo "You must specify a valid email address.";
      exit;
  }
  
  $email_body = "";
  $email_body = $email_body . "Name: " . $name . "&lt;br&gt;";
  $email_body = $email_body . "Email: " . $email . "&lt;br&gt;";
  $email_body = $email_body . "Phone: " . $phone . "&lt;br&gt;";
  $email_body = $email_body . "Message: " . $message;
  
  $mail-&gt;SetFrom($email, $name);
  $address = "email@domain.com";
  $mail-&gt;AddAddress($address, "A Name Here");
  $mail-&gt;Subject    = "Message from " . $name  . " on website contact form";
  $mail-&gt;MsgHTML($email_body);
  
  if(!$mail-&gt;Send()) {
    echo "There was a problem sending the email: " . $mail-&gt;ErrorInfo;
    exit;
  }
  
  header("Location: index.php?status=thanks");
  exit;
  }
  </code></pre>
  
  <p>The HTML is very simple:</p>
  
  <pre><code>&lt;form id="form" name="form" method="post" action="contact-process.php"&gt;
  
      &lt;?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?&gt;
        &lt;p class="form-thanks"&gt;Thank you for contacting us. We'll be in touch with you very soon.&lt;/p&gt;
      &lt;?php } ?&gt;
  
      &lt;label&gt;Name
      &lt;span class="small"&gt;First and Last&lt;/span&gt;
      &lt;/label&gt;
      &lt;input type="text" name="name" id="name" /&gt;
  
      &lt;label&gt;E-Mail
      &lt;span class="small"&gt;name@email.com&lt;/span&gt;
      &lt;/label&gt;
      &lt;input type="text" name="email" id="email" /&gt;
  
      &lt;label&gt;Phone Number
      &lt;span class="small"&gt;With area code&lt;/span&gt;
      &lt;/label&gt;
      &lt;input type="text" name="phone" id="phone" /&gt;
  
      &lt;label&gt;Message
      &lt;span class="small"&gt;How can we help you?&lt;/span&gt;
      &lt;/label&gt;
      &lt;textarea cols="40" rows="8" name="message"&gt;&lt;/textarea&gt;
  
      &lt;button type="submit"&gt;Submit&lt;/button&gt;
      &lt;div class="spacer"&gt;&lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>