title: PHP Mail Sending Blank Message On Page-Load
body: <p>I am having an issue with PHP Mailer. It is sending a blank email every time the page is loaded. </p>
  
  <p>I'm sure it's something simple (maybe missing a condition if submit button is hit) to fix this. </p>
  
  <p>Their documentation doesn't seem to have one though and the script first worked when I first used it but then started sending emails on page load after the first few times. Thanks!</p>
  
  <pre><code>&lt;form method="post" action=""&gt;
      &lt;div class="form-group"&gt;
          &lt;input name="name" type="text" class="form-control" placeholder="Enter Name"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;input name="email" type="email" class="form-control" placeholder="Enter Email"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;input name="subject" type="text" class="form-control" placeholder="Enter Subject"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
           &lt;textarea name="message" class="form-control" rows="5" placeholder="Enter Message"&gt;&lt;/textarea&gt;
      &lt;/div&gt;
      &lt;button name="submit" type="submit" value="submit" class="btn btn-submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;?php 
  
  require '/phpmailer/PHPMailerAutoload.php';
  require_once('/phpmailer/class.phpmailer.php');
  include("/phpmailer/class.smtp.php");
  
  $emailaddress = 'info@newpointdigital.com';
  
  $message=
      'Name:  '.$_POST['name'].'&lt;br /&gt;
      Email:  '.$_POST['email'].'&lt;br /&gt;
      Subject:    '.$_POST['subject'].'&lt;br /&gt;
      IP: '.$_SERVER['REMOTE_ADDR'].'&lt;br /&gt;&lt;br /&gt;
      Message:&lt;br /&gt;&lt;br /&gt;
      '.nl2br($_POST['message']).'
      ';
  
  $mail             = new PHPMailer();
  $mail-&gt;IsSMTP(); // telling the class to use SMTP
  $mail-&gt;Host       = "smtp.gmail.com"; // SMTP server
  //$mail-&gt;SMTPDebug  = 2;                     // 1 = errors and messages,2 = messages only
  $mail-&gt;SMTPAuth   = true;                  // enable SMTP authentication
  $mail-&gt;Host       = "smtp.gmail.com"; // sets the SMTP server
  $mail-&gt;Port       = 465;                    // set the SMTP port for the GMAIL server
  $mail-&gt;Username   = "info@newpointdigital.com"; // SMTP account username (the email account your created)
  $mail-&gt;Password   = "newpoint!@#$";        // SMTP account password (the password for the above email account)
  $mail-&gt;SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted
  
  $mail-&gt;CharSet  = 'UTF-8';  // so it interprets foreign characters
  $mail-&gt;SetFrom($_POST['email']);
  $mail-&gt;AddReplyTo($_POST['email']);
  $mail-&gt;Subject    = "Contact form from ".$_POST['name']." ";
  $mail-&gt;MsgHTML($message);
  
  $mail-&gt;AddAddress($emailaddress);
  
  if(!$mail-&gt;send()) {
      echo 'Message could not be sent.';
      echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
  } else {
      echo 'Message has been sent';
  }       
  ?&gt;
  </code></pre>