title: File attachment validation with PHPMailer
body: <p>I have an html form and I am using PHPMailer to email the form contents. In the form, I have a section for a file attachment. My requirements are that the file must be less than 2mb and it must be a pdf, doc or docx file. When I added in the validation if statement, my form stopped working:</p>
  
  <pre><code>if ((isset($_FILES['fileUpload']) &amp;&amp; $_FILES['fileUpload']['error'] == UPLOAD_ERR_OK) &amp;&amp; filesize($file) &lt; $maxsize &amp;&amp; in_array(mime_content_type($file), $types)) {
      $mail-&gt;AddAttachment($_FILES['fileUpload']['tmp_name'],
                           $_FILES['fileUpload']['name']);
  }
  </code></pre>
  
  <p>Here is the full PHP script:</p>
  
  <pre><code>&lt;?php
  
  require_once('assets/PHPMailer/class.phpmailer.php');
  
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $phone = $_POST['phone'];
  $email = $_POST['email'];
  $job = $_POST['job'];
  $file = $_FILES['fileUpload']['name'];
  
  
  $mail = new PHPMailer();
  
  $mail-&gt;From = "xxxxx";
  $mail-&gt;FromName  =  "xxxxx";
  $mail-&gt;AddAddress("xxxxx","xxxxx");
  
  $mail-&gt;WordWrap = 50;  
  
  $mail-&gt;Subject = "Job form";
  $mail-&gt;Body="
              First Name: $first_name
              Last Name: $last_name
              Email: $email
              Job: $job";
  
  $maxsize = 2 * 1024 * 1024;
  $types = array('application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
  
  
  if (isset($_FILES['fileUpload']) &amp;&amp; $_FILES['fileUpload']['error'] == UPLOAD_ERR_OK) &amp;&amp; filesize($file) &lt; $maxsize &amp;&amp; in_array(mime_content_type($file), $types) {
      $mail-&gt;AddAttachment($_FILES['fileUpload']['tmp_name'],
                           $_FILES['fileUpload']['name']);
  }
  
  
  if(!$mail-&gt;Send())
  {
     echo 'Message was not sent.';
     echo 'Mailer error: ' . $mail-&gt;ErrorInfo;
  }
  else
  {
     echo 'Thank you for your feedback.';
  }
  
  ?&gt;
  </code></pre>
  
  <p>Here is the HTML form:</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="jobform.php" method="POST"&gt;
      &lt;input type="text" name="first_name" value="First Name"&gt;
      &lt;input type="text" name="last_name" value="Last Name"&gt;
      &lt;input type="text" name="phone" value="Phone"&gt;&lt;br /&gt;
      &lt;input type="text" name="email" value="Email"&gt;
      &lt;select name="job"&gt;&lt;br /&gt;
          &lt;option&gt;Graphic Design Intern&lt;/option&gt;
          &lt;option&gt;ASP.Net Developer&lt;/opttion&gt;
          &lt;option&gt;Marketing Coordinator&lt;/option&gt;
          &lt;option&gt;Social Media Content Writer&lt;/option&gt;
      &lt;/select&gt;&lt;br /&gt;
      &lt;div&gt;&lt;h4&gt;Résumé&lt;/h4&gt;&lt;input type="file" name="fileUpload" /&gt;&lt;br /&gt;&lt;/div&gt;
      &lt;p&gt;&lt;/p&gt;
      &lt;input class="btn btn-large btn-success" type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>