PHP表单邮件附件

I am trying to fix one of the forms i am working on. I am not a developer so the other questions that where there were not really helpful as my code looks lot different than the one there.

The basic function that i am looking at is i have a form with multiple file upload fields.

here is the basic front end code:

 <form action="mailer.php" method="post" name="mainform" enctype="multipart/form-data">
    <table width="500" border="0" cellpadding="5" cellspacing="5">
       <tr>
        <th>Name:* </th>
        <td><input name="FName" type="text"></td>
    </tr>
    <tr>
    <tr>
        <th>Email:* </th>
        <td><input name="YEmail" type="text"></td>
    </tr>
    <tr>
        <th>Side 1 Text:* </th>
        <td><input name="S1Text" type="text"></td>
    </tr>
 <tr>
        <th>Side 2 Text:* </th>
        <td><input name="S2Text" type="text"></td>
    </tr>
    <tr>
        <th>Poker Chip:* </th>
        <td><select name="PokerChip" id="PokerChip">
        <option value="8 Stripe Inlay">8 Stripe Inlay</option>
        <option value="Hot Stamp Chip">Hot Stamp Chip</option>
        <option value="6 Stripe Direct Print">6 Stripe Direct Print</option>
        <option value="Clean Slate Ceramic">Clean Slate Ceramic</option>
        <option value="6 Stripe Deluxe Print">6 Stripe Deluxe Print</option>
        <option value="Dice Full Color Print">Dice Full Color Print</option>
        <option value="High Roller Rectangle">High Roller Rectangle</option>
        <option value="Tri-Color Clay">Tri-Color Clay</option>
        <option value="Pro Clay Hot Stamp">Pro Clay Hot Stamp</option>
            </select>
        </td>
    </tr>
    <tr>
        <th>Comments: </th>
        <td><textarea name="SpecialInstructions" cols="20" rows="4" id="SpecialInstructions"></textarea></td>
    </tr>
    <tr>
      <th>Upload File 1:</th>
      <td><input name="attachment" type="file">(File must be 10 MB or less)</td>
    </tr>
     <tr>
      <th>Upload File 2:</th>
      <td><input name="attachment2" type="file">(File must be 10 MB or less)</td>
    </tr>
    <tr>
        <td colspan="2" style="text-align:center;"><input type="submit" name="Submit" value="Send"></td>
    </tr>
    </table>
    </form>

Now the code in my mailer.php file is:

 <?php

$to_Email = "xxx"; //Replace with recipient email address
$subject = 'Virtual Proof Request Email';
$fromEmail = $_POST['YEmail']; 
$fromName = $_POST['FName']; 
$sidetext1 = $_POST['S1Text']; 
$sidetext2 = $_POST['S2Text']; 
$pokerchip = $_POST['PokerChip']; 
$specialinstructions = $_POST['SpecialInstructions'];
$message = "Name: $fromName

Email: $fromEmail

Side Text 1: $sidetext1

Side Text 2: $sidetext2

Poker Chip: $pokerchip

Special Instructions: $specialinstructions"; 



/* GET File Variables */ 
$tmpName = $_FILES['attachment']['tmp_name']; 
$fileType = $_FILES['attachment']['type']; 
$fileName = $_FILES['attachment']['name']; 

$tmpName2 = $_FILES['attachment2']['tmp_name']; 
$fileType2 = $_FILES['attachment2']['type']; 
$fileName2 = $_FILES['attachment2']['name']; 

/* Start of headers */ 
$headers = "From: $fromName $fromEmail"; 


if (file($tmpName)) { 
  /* Reading file ('rb' = read binary)  */
  $file = fopen($tmpName,'rb'); 
  $data = fread($file,filesize($tmpName)); 
  fclose($file); 


  /* a boundary string */
  $randomVal = md5(time()); 
  $mimeBoundary = "==Multipart_Boundary_x{$randomVal}x"; 

  /* Header for File Attachment */
  $headers .= "
MIME-Version: 1.0
"; 
  $headers .= "Content-Type: multipart/mixed;
" ;
  $headers .= " boundary=\"{$mimeBoundary}\""; 

  /* Multipart Boundary above message */
  $message = "This is a multi-part message in MIME format.

" . 
  "--{$mimeBoundary}
" . 
  "Content-Type: text/plain; charset=\"iso-8859-1\"
" . 
  "Content-Transfer-Encoding: 7bit

" . 
  $message . "

"; 


  /* Encoding file data */
  $data = chunk_split(base64_encode($data)); 

  /* Adding attchment-file to message*/
  $message .= "--{$mimeBoundary}
" . 
  "Content-Type: {$fileType};
" . 
  " name=\"{$fileName}\"
" . 
  "Content-Transfer-Encoding: base64

" . 
  $data . "

" . 
  "--{$mimeBoundary}--
"; 


} 

$flgchk = mail ("$to_Email", "$subject", "$message", "$headers"); 

if($flgchk){
  header ('Location: index.php?route=information/information&information_id=8');
 }
else{
  header ('Location: index.php?route=information/information&information_id=9');
}
?>

The problem is i receive just 1 attachment instead of 2.

I am not a programmer.. could anyone please guide me on this at the earliest??

Thanks a ton

File 2 is never handled.

The if is just checking for file 1 here: if (file($tmpName))

You need to copy the whole block with $tmpName changed to $tmpName2. The changes in the header just need to be done once, so you can delete them in the copied block.

Hope that gets you on the right track.