title: PHP email form with attachments not working
body: <p>I'm trying to use a PHP email form I found online that supports attachments, with a bit of extra code, but it's not working, I get a message saying "Sent", but no emails (I checked spam already).</p>
  
  <p>Here is the php file:</p>
  
  <pre><code>function multi_attach_mail($to, $subject, $message, $senderMail, $senderName, $files){
  
      $from = $senderName." &lt;".$senderMail."&gt;";
      $headers = "From: $from";
  
      // boundary
      $semi_rand = md5(time());
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  
      // headers for attachment
      $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
  
      // multipart boundary
      $message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
      "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
  
      // preparing attachments
      if(count($files) &gt; 0){
          for($i=0;$i&lt;count($files);$i++){
              if(is_file($files[$i])){
                  $message .= "--{$mime_boundary}\n";
                  $fp =    @fopen($files[$i],"rb");
                  $data =  @fread($fp,filesize($files[$i]));
                  @fclose($fp);
                  $data = chunk_split(base64_encode($data));
                  $message .= "Content-Type: application/octet-stream; name=\"".basename($files[$i])."\"\n" .
                  "Content-Description: ".basename($files[$i])."\n" .
                  "Content-Disposition: attachment;\n" . " filename=\"".basename($files[$i])."\"; size=".filesize($files[$i]).";\n" .
                  "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
              }
          }
      }
  
      $message .= "--{$mime_boundary}--";
      $returnpath = "-f" . $senderMail;
  
      //send email
      $mail = @mail($to, $subject, $message, $headers, $returnpath);
  
      //function return true, if email sent, otherwise return fasle
      if($mail){ return TRUE; } else { return FALSE; }
  
  }
  
  $message = "Customer Contact"
  . "\n" . "Name: " . $_POST['fullName']
  . "\n" . "Email: " . $_POST['email']
  . "\n" . "Phone: " . $_POST['phone']
  . "\n" . "Current Phone: " . $_POST['currentPhone']
  . "\n" . "Address: " . $_POST['address']
  . "\n" . "Retailer: " . $_POST['retailer']
  . "\n" . "Product Type: " . $_POST['productType']
  . "\n" . "Specific Item: " . $_POST['item']
  . "\n" . "Purchase Date: " . $_POST['purchaseDate']
  . "\n" . "Invoice Number: " . $_POST['invoiceNumber']
  . "\n" . "Issue: " . $_POST['issue']
  . "\n" . "How did the issue happen?: " . $_POST['how']
  . "\n" . "When did the issue occur?: " . $_POST['when']
  . "\n" . "Have you done anything to try correcting the issue?: " . $_POST['customerTry'];
  
  $to = 'someEmail@gmail.com';
  $from = $_POST['email'];
  $from_name = $_POST['fullName'];
  
  //attachment files path array
  $files = $_FILES['files'];
  $subject = 'Customer Contact From Service Form';
  $html_content = $message;
  
  //call multi_attach_mail() function and pass the required arguments
  $send_email = multi_attach_mail($to,$subject,$html_content,$from,$from_name,$files);
  
  //print message after email sent
  echo $send_email?"&lt;h1&gt; Mail Sent&lt;/h1&gt;&lt;br&gt;".$message:"&lt;h1&gt; Mail not SEND&lt;/h1&gt;";
  </code></pre>
  
  <p>My form looks like this:</p>
  
  <pre><code>&lt;form NOVALIDATE action="processContact.php" enctype="multipart/form-data" id="claimsForm" method="post" name="claimsForm"&gt;
    ..lots of fields...
    &lt;div class="form-group"&gt;
      &lt;label class="control-label claimsForm-field-header" for="customerTry"&gt;Photos:&lt;/label&gt;
      &lt;input type="file" id="files[]" name="files[]" multiple="multiple" /&gt;
      &lt;/div&gt;
  
      &lt;input class="green-btn" id="ss-submit" name="submit" type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The function came with the form I downloaded, so I don't think there is a problem with it. I've been playing around with the code and trying different things, but no luck (I'm not a PHP guy).</p>
  
  <p><strong>EDIT:</strong>
  Based on the suggestion below, I tried using phpMailer, following the example they have, here is my php file now:</p>
  
  <pre><code>/**
   * PHPMailer simple file upload and send example
   */
  $msg = '';
  
  $message = "Customer Contact"
  . "\n" . "Name: " . $_POST['fullName']
  . "\n" . "Email: " . $_POST['email']
  . "\n" . "Phone: " . $_POST['phone']
  . "\n" . "Current Phone: " . $_POST['currentPhone']
  . "\n" . "Address: " . $_POST['address']
  . "\n" . "Retailer: " . $_POST['retailer']
  . "\n" . "Product Type: " . $_POST['productType']
  . "\n" . "Specific Item: " . $_POST['item']
  . "\n" . "Purchase Date: " . $_POST['purchaseDate']
  . "\n" . "Invoice Number: " . $_POST['invoiceNumber']
  . "\n" . "Issue: " . $_POST['issue']
  . "\n" . "How did the issue happen?: " . $_POST['how']
  . "\n" . "When did the issue occur?: " . $_POST['when']
  . "\n" . "Have you done anything to try correcting the issue?: " . $_POST['customerTry'];
  
  $to = 'murtorius@gmail.com';
  $from = $_POST['email'];
  $from_name = $_POST['fullName'];
  
  //attachment files path array
  $files = $_FILES['userfile'];
  $subject = 'Customer Contact From Service Form';
  
  if (array_key_exists('userfile', $_FILES)) {
      // First handle the upload
      // Don't trust provided filename - same goes for MIME types
      // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
      $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
      if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
          // Upload handled successfully
          // Now create a message
          // This should be somewhere in your include_path
          require 'php-mailer/PHPMailerAutoload.php';
          $mail = new PHPMailer;
          $mail-&gt;setFrom($from, $from_name);
          $mail-&gt;addAddress($to, 'TEST');
          $mail-&gt;Subject = $subject;
          $mail-&gt;msgHTML($message);
          // Attach the uploaded file
          $mail-&gt;addAttachment($uploadfile, 'Photos');
          if (!$mail-&gt;send()) {
              $msg .= "Mailer Error: " . $mail-&gt;ErrorInfo;
          } else {
              $msg .= "Message sent!";
          }
      } else {
          $msg .= 'Failed to move file to ' . $uploadfile;
      }
  }
  </code></pre>
  
  <p>I changed the input file field name to 'userfile[]', but I get this:</p>
  
  <pre><code>Warning: sha1() expects parameter 1 to be string, array given in /home/zucora/service.zucora.com/processContact.php on line 35
  
  Warning: move_uploaded_file() expects parameter 1 to be string, array given in /home/zucora/service.zucora.com/processContact.php on line 36
  </code></pre>
  
  <p>If I change the name to 'userfile' (without []) I get a blank screen and no email.</p>