Send Mail with Multiple Attachment - Need Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepaks85
    New Member
    • Aug 2006
    • 114

    Send Mail with Multiple Attachment - Need Help

    Dear All,

    I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the code for attachment, I am not able to send anything. I get blank email.

    Can you please help me on this?

    Here is the html form:

    Code:
    <form name="frm" method="POST" enctype="multipart/form-data" action="sendemail.php">
    
    <div align="center">
      <center>
      <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="950" id="AutoNumber1">
        <tr>
          <td colspan="4">
          <img border="0" src="VHDInvoice_950.jpg" width="950" height="115"></td>
        </tr>
        <tr>
          <td colspan="4">
          <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="950" id="AutoNumber2" bgcolor="#FFFFFF">
            <tr>
              <td>
              
                                    <table border="0" cellpadding="5" cellspacing="0" style="border-style:solid; border-width:1; border-collapse: collapse" bordercolor="#2E3192" width="100%" id="AutoNumber2" class="data" height="1">
                  <tr>
                    <td height="46" valign="top" width="481">
                                       <table border="0" cellpadding="5" cellspacing="0" width="100%" style="border:1px solid #A3C2E2; border-collapse: collapse" bordercolor="#111111">
                      <tr>
                        <td width="50%">Destination Desk</td>
                        <td width="50%">
                        <select size="1" name="desdesk" style="font-family: Verdana; font-size: 8pt">
                        <option>--Select Destination Desk--</option>
                        <option value="Africa Desk">Africa Desk</option>
                        <option value="Australia Desk">Australia Desk</option>
                        <option value="Orient Desk">Orient Desk</option>
                        <option value="India Desk">India Desk</option>
                        <option value="South America Desk">South America Desk
                        </option>
                        </select></td>
                      </tr>
                      <tr>
                        <td width="50%">Booking Type</td>
                        <td width="50%">
                        <input type="radio" value="FIT" checked name="booktype"> FIT
                        <input type="radio" name="booktype" value="Brochure"> Brochure
                        <input type="radio" name="booktype" value="Group"> Group</td>
                      </tr>
                      <tr>
                        <td width="50%">Booking Agent Name</td>
                        <td width="50%">
                        <input name="bookingagent" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      </table>
                    
                    
                                      </td>
                    <td height="21" valign="top" rowspan="4" width="435">
                    
                                    
                    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber4" height="526">
                      <tr>
                        <td width="100%" height="205">
                        
                                            <table border="0" cellpadding="5" cellspacing="0" bordercolor="#111111" width="100%" id="AutoNumber3" style="border-collapse: collapse; border: 1px solid #A3C2E2">
                      <tr>
                        <td width="100%" colspan="2" bgcolor="#A3C2E2"><b>
                        Attachments</b></td>
                      </tr>
                      <tr>
                        <td width="50%">
                    CC Form/Insurance 
                    Form</td>
                        <td width="50%">
                        <input type="file" name="attachFile" size="20" style="font-family: Verdana; font-size: 8pt"></td>
                      </tr>
                      <tr>
                        <td width="50%">
                    Vendors 
                    Confirmation/Quote</td>
                        <td width="50%">
                        <input type="file" name="attachFile2" size="20" style="font-family: Verdana; font-size: 8pt"></td>
                      </tr>
                      <tr>
                        <td width="50%">
                    PIF Details</td>
                        <td width="50%">
                        <input type="file" name="attachFile3" size="20" style="font-family: Verdana; font-size: 8pt"></td>
                      </tr>
                      <tr>
                        <td width="50%">
                    Itinerary</td>
                        <td width="50%">
                        <input type="file" name="attachFile4" size="20" style="font-family: Verdana; font-size: 8pt"></td>
                      </tr>
                      <tr>
                        <td width="50%">
                    Proposal</td>
                        <td width="50%">
                        <input type="file" name="attachFile5" size="20" style="font-family: Verdana; font-size: 8pt"></td>
                      </tr>
                      <tr>
                        <td width="50%">
                        Rooming List 
                        for Group</td>
                        <td width="50%">
                        <input type="file" name="attachFile6" size="20" style="font-family: Verdana; font-size: 8pt"></td>
                      </tr>
                      </table>
                                            </td>
                      </tr>
                      <tr>
                        <td width="100%" height="13"></td>
                      </tr>
                      <tr>
                        <td width="100%" height="204">
                                            <table border="0" cellpadding="6" cellspacing="0" style="border:1px solid #A3C2E2; border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" height="117">
                      <tr>
                        <td width="100%" colspan="2" bgcolor="#A3C2E2" height="13"><b>Invoice</b></td>
                      </tr>
                      <tr>
                        <td width="50%" height="17">Land Price Per Person</td>
                        <td width="50%" height="17">
                        <input name="landprice" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="50%" height="17">Airfare</td>
                        <td width="50%" height="17">
                        <input name="airfare" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="50%" height="17">Markup</td>
                        <td width="50%" height="17">
                        <input name="markup" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="50%" height="17">Departure Taxes</td>
                        <td width="50%" height="17">
                        <input name="invdeptax" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="100%" colspan="2" height="1">
                        <input type="radio" name="insurance" value="Accepted" onclick="showstuff('3')"> Insurance Accepted 
                        <input type="radio" name="insurance" value="Decline" onclick="hidestuff('3')"> Insurance Decline</td>
                      </tr>
                      <tr id="3" style="display: none">
                        <td width="50%" height="1" valign="top">Insurance Amount</td>
                        <td width="50%" height="1" valign="top">
                        <input name="incamt" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                    </table>
                        
                                            
                        </td>
                      </tr>
                      <tr>
                        <td width="100%" height="13">
                        
                        
                        </td>
                      </tr>
                      <tr>
                        <td width="100%" valign="top" height="91"> 
                                            
                        <table border="0" cellpadding="6" cellspacing="0" style="border:1px solid #A3C2E2; border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" height="117">
                      <tr>
                        <td width="100%" colspan="2" bgcolor="#A3C2E2" height="13">
                        <b>Other Details</b></td>
                      </tr>
                      <tr>
                        <td width="50%" height="17" valign="top">Instructions<p>&nbsp;</td>
                        <td width="50%" height="17">
                        <textarea rows="6" name="instruction" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
                      </tr>
                      <tr>
                        <td width="50%" height="17" valign="top">Other Instructions<p>&nbsp;</td>
                        <td width="50%" height="17">
                        <textarea rows="6" name="other" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
                      </tr>
                      </table>
                        
                        
                        
                        </td>
                      </tr>
                      </table>
                    
                    
                    
                    </td>
                  </tr>
                  <tr>
                    <td height="2" valign="top" width="481">
                    <input type="radio" name="travdetails" value="Direct Traveler" onClick="agency();"> Direct 
                     Traveler 
                    <input type="radio" name="travdetails" value="Agency" onClick="traveler();"> 
                     Agency</td>
                    </tr>
                  <tr>
                    <td height="234" valign="top" width="481">
                          
                    <table border="0" cellpadding="6" cellspacing="0" style="border:1px solid #A3C2E2; border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" id="agency" name="agency">
                      <tr>
                        <td width="100%" colspan="2" bgcolor="#A3C2E2"><b>Agency 
                        Details</b></td>
                      </tr>
                      <tr>
                        <td width="50%">Agency Name</td>
                        <td width="50%">
                        <input name="agencyname" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="50%">IATA</td>
                        <td width="50%">
                        <input name="iata" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="50%">Agent</td>
                        <td width="50%">
                        <input name="agent" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="50%">Address</td>
                        <td width="50%">
                        <textarea rows="4" name="agencyadd" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
                      </tr>
                      <tr>
                        <td width="50%">Tel</td>
                        <td width="50%">
                        <input name="agencytel" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="50%">Fax</td>
                        <td width="50%">
                        <input name="agencyfax" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="50%">Email</td>
                        <td width="50%">
                        <input name="agencyemail" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                    </table>   
                    
                                     </td>
                    </tr>
                  <tr>
                    <td valign="top" width="481">
                      
                      
                      
                        <table border="0" cellpadding="6" cellspacing="0" style="border:1px solid #A3C2E2; border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" id="traveler" name="traveler">
                      <tr>
                        <td width="100%" colspan="2" bgcolor="#A3C2E2"><b>Traveler 
                        Details</b></td>
                      </tr>
                      <tr>
                        <td width="50%">Total Number of Traveler</td>
                        <td width="50%">
                        <input name="notraveler" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="50%">Traveler Name</td>
                        <td width="50%">
                        <textarea rows="3" name="travnames" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
                      </tr>
                      <tr>
                        <td width="50%">Address</td>
                        <td width="50%">
                        <textarea rows="4" name="travadd" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
                      </tr>
                      <tr>
                        <td width="50%">Departure Date</td>
                        <td width="50%">
                        <input name="travdepdate" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
                      </tr>
                      <tr>
                        <td width="50%">Nett Payouts</td>
                        <td width="50%">
                        <textarea rows="5" name="nettpay" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
                      </tr>
                    </table>              
                    
                                    
                    </td>
                    </tr>
                  <tr>
                    <td height="23" valign="top" width="481">
                    <p align="right">
                  <input type="submit" value="Submit" name="submit" style="font-family: Verdana; font-size: 8pt; font-weight: bold; color: #2E3192; border-style: solid; border-width: 1; padding: 2; background-color: #A3C2E2"></td>
                    <td height="23" valign="top" width="435">
                    <input type="reset" value="Reset" name="reset" style="font-family: Verdana; font-size: 8pt; font-weight: bold; color: #2E3192; border-style: solid; border-width: 1; padding: 2; background-color: #A3C2E2"></td>
                  </tr>
                  </table>
    
                        </td>
            </tr>
            <tr>
              <td bgcolor="#2E3192">
                  <p align="right"><font color="#FFFFFF">2008 OnlineRes Inc. All 
                  rights reserved.</font></td>
            </tr>
          </table>
          </td>
        </tr>
    
      </table>
      </center>
    </div>
    
    
    </form>
    ------------------------------------------------------------------------------

    Here is the sendemail.php file:

    Code:
    <?
                $booktype = $_POST['booktype']; 
                $bookingagent = $_POST['bookingagent']; 
                $travdetails = $_POST['travdetails'];
                $agencyname = $_POST['agencyname'];
                
                $iata = $_POST['iata'];
                $agent = $_POST['agent'];
                $agencyadd = $_POST['agencyadd'];
                $agencytel = $_POST['agencytel'];
                $agencyfax = $_POST['agencyfax'];
                
                $agencyemail = $_POST['agencyemail'];
                $notraveler = $_POST['notraveler'];
                $travnames = $_POST['travnames'];
                $travadd = $_POST['travadd'];
                $travdepdate = $_POST['travdepdate'];
                $nettpay = $_POST['nettpay'];
                
                $landprice = $_POST['landprice'];
                $airfare = $_POST['airfare'];
                $markup = $_POST['markup'];
                $invdeptax = $_POST['invdeptax'];
                $insurance = $_POST['insurance'];
                            
                $incamt = $_POST['incamt'];
                $instruction = $_POST['instruction'];
                $other = $_POST['other'];
    
    
    
                        switch($_POST['desdesk']){
    
                case 'Africa Desk':
    
                   $deskname = "Africa Desk";
                   //$deskEmail = "africadesk@sitanet.com";
                   $deskEmail = "deepaks@onlineres.com";
                   
    
                   break;
    
                case 'Australia Desk':
    
                   $deskname = "Australia Desk";
                   $deskEmail = "australiadesk@sitanet.com";
                   
                   break;
    
                case 'India Desk':
    
                   $deskname = "India Desk";
                   $deskEmail = "indiadesk@sitanet.com";
    
                   break;
    
                case 'Orient Desk':
    
                   $deskname = "Orient Desk";
                   $deskEmail = "orientdesk@sitanet.com";
    
                   break;
    
                case 'South America Desk':
    
                   $deskname = "South America Desk";
                   $deskEmail = "southamericadesk@sitanet.com";
    
                   break;
    
                case 'Ticketing Help Desk':
    
                   $deskname = "Ticketing Help Desk";
                   $deskEmail = "ticketinghd@sitanet.com";
    
                   break;
    
                default:
    
                   $deskname = "Vacation Help Desk";
                   $deskEmail = "vacationshd@sitanet.com";
    
             }
    
    
    
           $body = "$deskname\n$booktype\n$bookingagent\n$landprice\n$airfare\n$markup\n$invdeptax<\nInsurance: $insurance\n$incamt\n$instruction\n$other\n$travdetails";
           $body .= "$agencyname\n$iata\n$agent\n$agencyadd\n$agencytel\n$agencyfax\n$agencyemail\n$notraveler\n$travnames\n$travadd\n$travdepdate\n$nettpay\n";
           
      
            
    	      $to=$deskEmail;
    	      $cc = "arunendram@onlineres.com";
            
            $subject="Vacation Help Desk New Reservation Form";
    
    	      // get the sender's name and email address
    	      // we'll just plug them a variable to be used later
    	      $from = "Site Update <siteupdate@sitanet.com>";
    
    	      // generate a random string to be used as the boundary marker
    	      $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
    
    	      // now we'll build the message headers
    	      $headers = "From: $from\r\n" .
    	      "MIME-Version: 1.0\r\n" .
    	         "Content-Type: multipart/mixed;\r\n" .
    	         " boundary=\"{$mime_boundary}\"";
            
            $headers .= "CC: $cc\r\n";
    	      // here, we'll start the message body.
    	      // this is the text that will be displayed
    	      // in the e-mail
    	      $message=$body;
    
    	      // next, we'll build the invisible portion of the message body
    	      // note that we insert two dashes in front of the MIME boundary
    	      // when we use it
    	      $message = "This is a multi-part message in MIME format.\n\n" .
    	         "--{$mime_boundary}\n" .
    	         "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
    	         "Content-Transfer-Encoding: 7bit\n\n" .
    	      $message . "\n\n";
    
    	      // now we'll process our uploaded files
    	      foreach($_FILES as $userfile)
    	      {
    	         // store the file information to variables for easier access
    	         $tmp_name = $userfile['tmp_name'];
    	         $type = $userfile['type'];
    	         $name = $userfile['name'];
    	         $size = $userfile['size'];
    
    	        // echo $tmp_name."\n\n";
    
    	         // if the upload succeded, the file will exist
    	         if (file_exists($tmp_name))
    	         {
    
    	           if(is_uploaded_file($tmp_name))
    	            {
    
    	               // open the file for a binary read
    	               $file = fopen($tmp_name,'rb');
    
    	               // read the file content into a variable
    	               $data = fread($file,filesize($tmp_name));
    
    	               // close the file
    	               fclose($file);
    
    	               // now we encode it and split it into acceptable length lines
    	               $data = chunk_split(base64_encode($data));
    	            }
    
    	            // now we'll insert a boundary to indicate we're starting the attachment
    	            // we have to specify the content type, file name, and disposition as
    	            // an attachment, then add the file content.
    	            // NOTE: we don't set another boundary to indicate that the end of the
    	            // file has been reached here. we only want one boundary between each file
    	            // we'll add the final one after the loop finishes.
    	            $message .= "--{$mime_boundary}\n" .
    	               "Content-Type: {$type};\n" .
    	               " name=\"{$name}\"\n" .
    	               "Content-Disposition: attachment;\n" .
    	               " filename=\"{$fileatt_name}\"\n" .
    	               "Content-Transfer-Encoding: base64\n\n" .
    	            $data . "\n\n";
    	         }
    	      }
    	      // here's our closing mime boundary that indicates the last of the message
    	      $message.="--{$mime_boundary}--\n";
    	      // now we just send the message
    	      if (@mail($to, $subject, $message, $headers))
    	      {
    	 		?>
    	    		<script>
    	    			
    		  			document.location = "submitForm.htm";
    		 		</script>
    		  	<?}
    
    		else
    			{
    			?>
    				<script>
    					alert("Message Not Sent, Please Try Again.");
    		 			document.location = "indexbrowse.htm";
    		  		</script>
    	  		<?}
           ///////////////////////////////////////////
    ?>
    Please advise where I am doing wrong?

    You can also view the html form here:



    Thanks

    Deepak
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    For complex mails like that, I would recommend that you abandon the mail() function altogether and start using one of the PHP mailer classes.

    They are usually a lot easier to work with if you intend to do anything more than send text mails.

    I would try either PHPMailer or Swift Mailer. See how that works out.

    Comment

    Working...