title: white mail if no attachment
body: <p>I have a partially working email code (don't come with the phpmailer stuff), it is sending emails WITH attachments, but once I send a file without an attachment it does send but with a WHITE, no text.</p>
  
  <p>Why is it sending a white email if I only send text:</p>
  
  <p>This is the form all within a query:</p>
  
  <pre><code>while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
      // output data of each row
          echo "
          &lt;form method='post' name='contact_form'
      action='/bedankt-verzenden?id=". $id ."' enctype='multipart/form-data'&gt;
          Naar wie verzend u het voorstel:&lt;br /&gt;
          &lt;input style='width: 100%;' type='text' name='name' value='" . $row["firstname"] . "'&gt;&lt;br/&gt;&lt;br /&gt;
          Email:&lt;br /&gt;
          &lt;input style='width: 100%;' type='text' name='email' value='Jouw email'&gt;&lt;br /&gt;&lt;br /&gt;
          Onderwerp van het bericht:&lt;br /&gt;
          &lt;input style='width: 100%;' type='text' name='title' value='Offerte voor uw ". $row["stijlkeuken"] ." keuken'&gt;&lt;br /&gt;&lt;br /&gt;
          Bericht:&lt;br /&gt;
          &lt;textarea style='width: 100%; height: 200px;' name='message'&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
          Bestand uploaden:&lt;br /&gt;
          &lt;input type='file' name='File_upload[]' size='40' multiple='multiple' &gt;&lt;br /&gt;&lt;br /&gt;
          &lt;input style='width: 100%; display: none;' type='text' name='email2' value='". $row["email"] ."'&gt;
          &lt;input type='submit' value='Verzenden' class='clicky-submitty' id='clicky-submitty2'&gt;
          &lt;/form&gt;";
  
  }
  </code></pre>
  
  <p>Then this is the handler (edited), also within a query:</p>
  
  <pre><code>while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  
      $recipient_email    = $_POST['email2']; //recepient
      $from_email         = $_POST['email']; //from email using site domain.
      $subject            = $_POST['title']; //email subject line
  
      $sender_email = filter_var($_POST["email"], FILTER_SANITIZE_STRING); //capture sender email
      $sender_message = filter_var($_POST['message'], FILTER_SANITIZE_STRING); //capture message
      $attachments = $_FILES['File_upload'];
  
      $file_count = count($attachments['name']); //count total files attached
      $boundary = md5(time());
      $eol = "\r\n";
  
  if(empty($_FILES['File_upload']))
  {
  
      //header
          $headers = 'From: info@keukenaanbod.nl' . $eol; 
          $headers .= 'Reply-To: '. $sender_email . $eol;
          $headers .= 'Cc: ' . $sender_email . $eol;
          $headers .= "Message-ID: &lt;" . time() . " TheSystem@" . $_SERVER['SERVER_NAME'] . "&gt;" . $eol; 
          $headers .= "X-Mailer: PHP v" . phpversion() . $eol;
          $headers .= 'MIME-Version: 1.0' . $eol;
          $headers .= "Content-type:text/html; charset=UTF-8 boundary=\"" . $boundary . "\"";
  
  
                  $body = "--". $boundary . $eol;
                  $body .= "Content-type:text/plain; charset=iso-8859-1" . $eol;
                  $body .= "Content-Transfer-Encoding: 7bit" . $eol . $eol;
                  $body .= "Er is gereageerd op jouw keuken aanvraag, reageer op deze mail om in contact te komen:". $eol . $sender_message . $eol . $eol;
  
      }else{  
  
          //header
          $headers = 'From: info@keukenaanbod.nl' . $eol; 
          $headers .= 'Reply-To: '. $sender_email . $eol;
          $headers .= 'Cc: ' . $sender_email . $eol;
          $headers .= "Message-ID: &lt;" . time() . " TheSystem@" . $_SERVER['SERVER_NAME'] . "&gt;" . $eol; 
          $headers .= "X-Mailer: PHP v" . phpversion() . $eol;
          $headers .= 'MIME-Version: 1.0' . $eol;
          $headers .= "Content-Type: multipart/mixed; boundary=\"" . $boundary . "\""; 
  
          //attachments
          for ($x = 0; $x &lt; $file_count; $x++){      
              if(!empty($attachments['name'][$x])){
  
                  //get file info
                  $file_name = $attachments['name'][$x];
                  $file_size = $attachments['size'][$x];
                  $file_type = $attachments['type'][$x];
  
                  //read file
                  $handle = fopen($attachments['tmp_name'][$x], "r");
                  $content = fread($handle, $file_size);
                  fclose($handle);
                  $encoded_content = chunk_split(base64_encode($content)); //split into smaller chunks (RFC 2045)
  
                  $body = "--". $boundary . $eol;
                  $body .= "Content-type:text/plain; charset=iso-8859-1" . $eol;
                  $body .= "Content-Transfer-Encoding: 7bit" . $eol . $eol;
                  $body .= "Er is gereageerd op jouw keuken aanvraag, reageer op deze mail om in contact te komen:". $eol . $sender_message . $eol . $eol;
                  $body .= "--" . $boundary . $eol;
                  $body .= "Content-Type: " . $file_type. "; name=\"" . $file_name . "\"" . $eol;
                  $body .= "Content-Transfer-Encoding: base64" . $eol; 
                  $body .= "Content-Disposition: attachment; filename=\"" . $file_name . "\"" . $eol . $eol;
                  $body .= $encoded_content . $eol . $eol;
              }
          }
      }
  
  
       $sentMail = @mail($recipient_email, $subject, $body, $headers);
      if($sentMail) //output success or failure messages
      {      
          header('Location: /verzenden-gelukt?id='. $id .'');
      }else{
          die('Email kon helaas niet verzonden worden, u dient direct uit te zoeken wat er gaande is!');  
      }
  }
  </code></pre>