469,081 Members | 1,498 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,081 developers. It's quick & easy.

Send Mail with Multiple Attachment - Need Help

114 100+
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <form name="frm" method="POST" enctype="multipart/form-data" action="sendemail.php">
  3.  
  4. <div align="center">
  5.   <center>
  6.   <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="950" id="AutoNumber1">
  7.     <tr>
  8.       <td colspan="4">
  9.       <img border="0" src="VHDInvoice_950.jpg" width="950" height="115"></td>
  10.     </tr>
  11.     <tr>
  12.       <td colspan="4">
  13.       <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="950" id="AutoNumber2" bgcolor="#FFFFFF">
  14.         <tr>
  15.           <td>
  16.  
  17.                                 <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">
  18.               <tr>
  19.                 <td height="46" valign="top" width="481">
  20.                                    <table border="0" cellpadding="5" cellspacing="0" width="100%" style="border:1px solid #A3C2E2; border-collapse: collapse" bordercolor="#111111">
  21.                   <tr>
  22.                     <td width="50%">Destination Desk</td>
  23.                     <td width="50%">
  24.                     <select size="1" name="desdesk" style="font-family: Verdana; font-size: 8pt">
  25.                     <option>--Select Destination Desk--</option>
  26.                     <option value="Africa Desk">Africa Desk</option>
  27.                     <option value="Australia Desk">Australia Desk</option>
  28.                     <option value="Orient Desk">Orient Desk</option>
  29.                     <option value="India Desk">India Desk</option>
  30.                     <option value="South America Desk">South America Desk
  31.                     </option>
  32.                     </select></td>
  33.                   </tr>
  34.                   <tr>
  35.                     <td width="50%">Booking Type</td>
  36.                     <td width="50%">
  37.                     <input type="radio" value="FIT" checked name="booktype"> FIT
  38.                     <input type="radio" name="booktype" value="Brochure"> Brochure
  39.                     <input type="radio" name="booktype" value="Group"> Group</td>
  40.                   </tr>
  41.                   <tr>
  42.                     <td width="50%">Booking Agent Name</td>
  43.                     <td width="50%">
  44.                     <input name="bookingagent" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  45.                   </tr>
  46.                   </table>
  47.  
  48.  
  49.                                   </td>
  50.                 <td height="21" valign="top" rowspan="4" width="435">
  51.  
  52.  
  53.                 <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber4" height="526">
  54.                   <tr>
  55.                     <td width="100%" height="205">
  56.  
  57.                                         <table border="0" cellpadding="5" cellspacing="0" bordercolor="#111111" width="100%" id="AutoNumber3" style="border-collapse: collapse; border: 1px solid #A3C2E2">
  58.                   <tr>
  59.                     <td width="100%" colspan="2" bgcolor="#A3C2E2"><b>
  60.                     Attachments</b></td>
  61.                   </tr>
  62.                   <tr>
  63.                     <td width="50%">
  64.                 CC Form/Insurance 
  65.                 Form</td>
  66.                     <td width="50%">
  67.                     <input type="file" name="attachFile" size="20" style="font-family: Verdana; font-size: 8pt"></td>
  68.                   </tr>
  69.                   <tr>
  70.                     <td width="50%">
  71.                 Vendors 
  72.                 Confirmation/Quote</td>
  73.                     <td width="50%">
  74.                     <input type="file" name="attachFile2" size="20" style="font-family: Verdana; font-size: 8pt"></td>
  75.                   </tr>
  76.                   <tr>
  77.                     <td width="50%">
  78.                 PIF Details</td>
  79.                     <td width="50%">
  80.                     <input type="file" name="attachFile3" size="20" style="font-family: Verdana; font-size: 8pt"></td>
  81.                   </tr>
  82.                   <tr>
  83.                     <td width="50%">
  84.                 Itinerary</td>
  85.                     <td width="50%">
  86.                     <input type="file" name="attachFile4" size="20" style="font-family: Verdana; font-size: 8pt"></td>
  87.                   </tr>
  88.                   <tr>
  89.                     <td width="50%">
  90.                 Proposal</td>
  91.                     <td width="50%">
  92.                     <input type="file" name="attachFile5" size="20" style="font-family: Verdana; font-size: 8pt"></td>
  93.                   </tr>
  94.                   <tr>
  95.                     <td width="50%">
  96.                     Rooming List 
  97.                     for Group</td>
  98.                     <td width="50%">
  99.                     <input type="file" name="attachFile6" size="20" style="font-family: Verdana; font-size: 8pt"></td>
  100.                   </tr>
  101.                   </table>
  102.                                         </td>
  103.                   </tr>
  104.                   <tr>
  105.                     <td width="100%" height="13"></td>
  106.                   </tr>
  107.                   <tr>
  108.                     <td width="100%" height="204">
  109.                                         <table border="0" cellpadding="6" cellspacing="0" style="border:1px solid #A3C2E2; border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" height="117">
  110.                   <tr>
  111.                     <td width="100%" colspan="2" bgcolor="#A3C2E2" height="13"><b>Invoice</b></td>
  112.                   </tr>
  113.                   <tr>
  114.                     <td width="50%" height="17">Land Price Per Person</td>
  115.                     <td width="50%" height="17">
  116.                     <input name="landprice" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  117.                   </tr>
  118.                   <tr>
  119.                     <td width="50%" height="17">Airfare</td>
  120.                     <td width="50%" height="17">
  121.                     <input name="airfare" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  122.                   </tr>
  123.                   <tr>
  124.                     <td width="50%" height="17">Markup</td>
  125.                     <td width="50%" height="17">
  126.                     <input name="markup" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  127.                   </tr>
  128.                   <tr>
  129.                     <td width="50%" height="17">Departure Taxes</td>
  130.                     <td width="50%" height="17">
  131.                     <input name="invdeptax" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  132.                   </tr>
  133.                   <tr>
  134.                     <td width="100%" colspan="2" height="1">
  135.                     <input type="radio" name="insurance" value="Accepted" onclick="showstuff('3')"> Insurance Accepted 
  136.                     <input type="radio" name="insurance" value="Decline" onclick="hidestuff('3')"> Insurance Decline</td>
  137.                   </tr>
  138.                   <tr id="3" style="display: none">
  139.                     <td width="50%" height="1" valign="top">Insurance Amount</td>
  140.                     <td width="50%" height="1" valign="top">
  141.                     <input name="incamt" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  142.                   </tr>
  143.                 </table>
  144.  
  145.  
  146.                     </td>
  147.                   </tr>
  148.                   <tr>
  149.                     <td width="100%" height="13">
  150.  
  151.  
  152.                     </td>
  153.                   </tr>
  154.                   <tr>
  155.                     <td width="100%" valign="top" height="91"> 
  156.  
  157.                     <table border="0" cellpadding="6" cellspacing="0" style="border:1px solid #A3C2E2; border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" height="117">
  158.                   <tr>
  159.                     <td width="100%" colspan="2" bgcolor="#A3C2E2" height="13">
  160.                     <b>Other Details</b></td>
  161.                   </tr>
  162.                   <tr>
  163.                     <td width="50%" height="17" valign="top">Instructions<p>&nbsp;</td>
  164.                     <td width="50%" height="17">
  165.                     <textarea rows="6" name="instruction" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
  166.                   </tr>
  167.                   <tr>
  168.                     <td width="50%" height="17" valign="top">Other Instructions<p>&nbsp;</td>
  169.                     <td width="50%" height="17">
  170.                     <textarea rows="6" name="other" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
  171.                   </tr>
  172.                   </table>
  173.  
  174.  
  175.  
  176.                     </td>
  177.                   </tr>
  178.                   </table>
  179.  
  180.  
  181.  
  182.                 </td>
  183.               </tr>
  184.               <tr>
  185.                 <td height="2" valign="top" width="481">
  186.                 <input type="radio" name="travdetails" value="Direct Traveler" onClick="agency();"> Direct 
  187.                  Traveler 
  188.                 <input type="radio" name="travdetails" value="Agency" onClick="traveler();"> 
  189.                  Agency</td>
  190.                 </tr>
  191.               <tr>
  192.                 <td height="234" valign="top" width="481">
  193.  
  194.                 <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">
  195.                   <tr>
  196.                     <td width="100%" colspan="2" bgcolor="#A3C2E2"><b>Agency 
  197.                     Details</b></td>
  198.                   </tr>
  199.                   <tr>
  200.                     <td width="50%">Agency Name</td>
  201.                     <td width="50%">
  202.                     <input name="agencyname" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  203.                   </tr>
  204.                   <tr>
  205.                     <td width="50%">IATA</td>
  206.                     <td width="50%">
  207.                     <input name="iata" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  208.                   </tr>
  209.                   <tr>
  210.                     <td width="50%">Agent</td>
  211.                     <td width="50%">
  212.                     <input name="agent" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  213.                   </tr>
  214.                   <tr>
  215.                     <td width="50%">Address</td>
  216.                     <td width="50%">
  217.                     <textarea rows="4" name="agencyadd" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
  218.                   </tr>
  219.                   <tr>
  220.                     <td width="50%">Tel</td>
  221.                     <td width="50%">
  222.                     <input name="agencytel" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  223.                   </tr>
  224.                   <tr>
  225.                     <td width="50%">Fax</td>
  226.                     <td width="50%">
  227.                     <input name="agencyfax" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  228.                   </tr>
  229.                   <tr>
  230.                     <td width="50%">Email</td>
  231.                     <td width="50%">
  232.                     <input name="agencyemail" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  233.                   </tr>
  234.                 </table>   
  235.  
  236.                                  </td>
  237.                 </tr>
  238.               <tr>
  239.                 <td valign="top" width="481">
  240.  
  241.  
  242.  
  243.                     <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">
  244.                   <tr>
  245.                     <td width="100%" colspan="2" bgcolor="#A3C2E2"><b>Traveler 
  246.                     Details</b></td>
  247.                   </tr>
  248.                   <tr>
  249.                     <td width="50%">Total Number of Traveler</td>
  250.                     <td width="50%">
  251.                     <input name="notraveler" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  252.                   </tr>
  253.                   <tr>
  254.                     <td width="50%">Traveler Name</td>
  255.                     <td width="50%">
  256.                     <textarea rows="3" name="travnames" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
  257.                   </tr>
  258.                   <tr>
  259.                     <td width="50%">Address</td>
  260.                     <td width="50%">
  261.                     <textarea rows="4" name="travadd" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
  262.                   </tr>
  263.                   <tr>
  264.                     <td width="50%">Departure Date</td>
  265.                     <td width="50%">
  266.                     <input name="travdepdate" size="21" style="font-family: Verdana; font-size: 8pt; border: 1px solid #666666; "></td>
  267.                   </tr>
  268.                   <tr>
  269.                     <td width="50%">Nett Payouts</td>
  270.                     <td width="50%">
  271.                     <textarea rows="5" name="nettpay" cols="33" style="font-family: Verdana; font-size: 8pt"></textarea></td>
  272.                   </tr>
  273.                 </table>              
  274.  
  275.  
  276.                 </td>
  277.                 </tr>
  278.               <tr>
  279.                 <td height="23" valign="top" width="481">
  280.                 <p align="right">
  281.               <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>
  282.                 <td height="23" valign="top" width="435">
  283.                 <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>
  284.               </tr>
  285.               </table>
  286.  
  287.                     </td>
  288.         </tr>
  289.         <tr>
  290.           <td bgcolor="#2E3192">
  291.               <p align="right"><font color="#FFFFFF">2008 OnlineRes Inc. All 
  292.               rights reserved.</font></td>
  293.         </tr>
  294.       </table>
  295.       </td>
  296.     </tr>
  297.  
  298.   </table>
  299.   </center>
  300. </div>
  301.  
  302.  
  303. </form>
  304.  
  305.  
------------------------------------------------------------------------------

Here is the sendemail.php file:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3.             $booktype = $_POST['booktype']; 
  4.             $bookingagent = $_POST['bookingagent']; 
  5.             $travdetails = $_POST['travdetails'];
  6.             $agencyname = $_POST['agencyname'];
  7.  
  8.             $iata = $_POST['iata'];
  9.             $agent = $_POST['agent'];
  10.             $agencyadd = $_POST['agencyadd'];
  11.             $agencytel = $_POST['agencytel'];
  12.             $agencyfax = $_POST['agencyfax'];
  13.  
  14.             $agencyemail = $_POST['agencyemail'];
  15.             $notraveler = $_POST['notraveler'];
  16.             $travnames = $_POST['travnames'];
  17.             $travadd = $_POST['travadd'];
  18.             $travdepdate = $_POST['travdepdate'];
  19.             $nettpay = $_POST['nettpay'];
  20.  
  21.             $landprice = $_POST['landprice'];
  22.             $airfare = $_POST['airfare'];
  23.             $markup = $_POST['markup'];
  24.             $invdeptax = $_POST['invdeptax'];
  25.             $insurance = $_POST['insurance'];
  26.  
  27.             $incamt = $_POST['incamt'];
  28.             $instruction = $_POST['instruction'];
  29.             $other = $_POST['other'];
  30.  
  31.  
  32.  
  33.                     switch($_POST['desdesk']){
  34.  
  35.             case 'Africa Desk':
  36.  
  37.                $deskname = "Africa Desk";
  38.                //$deskEmail = "africadesk@sitanet.com";
  39.                $deskEmail = "deepaks@onlineres.com";
  40.  
  41.  
  42.                break;
  43.  
  44.             case 'Australia Desk':
  45.  
  46.                $deskname = "Australia Desk";
  47.                $deskEmail = "australiadesk@sitanet.com";
  48.  
  49.                break;
  50.  
  51.             case 'India Desk':
  52.  
  53.                $deskname = "India Desk";
  54.                $deskEmail = "indiadesk@sitanet.com";
  55.  
  56.                break;
  57.  
  58.             case 'Orient Desk':
  59.  
  60.                $deskname = "Orient Desk";
  61.                $deskEmail = "orientdesk@sitanet.com";
  62.  
  63.                break;
  64.  
  65.             case 'South America Desk':
  66.  
  67.                $deskname = "South America Desk";
  68.                $deskEmail = "southamericadesk@sitanet.com";
  69.  
  70.                break;
  71.  
  72.             case 'Ticketing Help Desk':
  73.  
  74.                $deskname = "Ticketing Help Desk";
  75.                $deskEmail = "ticketinghd@sitanet.com";
  76.  
  77.                break;
  78.  
  79.             default:
  80.  
  81.                $deskname = "Vacation Help Desk";
  82.                $deskEmail = "vacationshd@sitanet.com";
  83.  
  84.          }
  85.  
  86.  
  87.  
  88.        $body = "$deskname\n$booktype\n$bookingagent\n$landprice\n$airfare\n$markup\n$invdeptax<\nInsurance: $insurance\n$incamt\n$instruction\n$other\n$travdetails";
  89.        $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";
  90.  
  91.  
  92.  
  93.           $to=$deskEmail;
  94.           $cc = "arunendram@onlineres.com";
  95.  
  96.         $subject="Vacation Help Desk New Reservation Form";
  97.  
  98.           // get the sender's name and email address
  99.           // we'll just plug them a variable to be used later
  100.           $from = "Site Update <siteupdate@sitanet.com>";
  101.  
  102.           // generate a random string to be used as the boundary marker
  103.           $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
  104.  
  105.           // now we'll build the message headers
  106.           $headers = "From: $from\r\n" .
  107.           "MIME-Version: 1.0\r\n" .
  108.              "Content-Type: multipart/mixed;\r\n" .
  109.              " boundary=\"{$mime_boundary}\"";
  110.  
  111.         $headers .= "CC: $cc\r\n";
  112.           // here, we'll start the message body.
  113.           // this is the text that will be displayed
  114.           // in the e-mail
  115.           $message=$body;
  116.  
  117.           // next, we'll build the invisible portion of the message body
  118.           // note that we insert two dashes in front of the MIME boundary
  119.           // when we use it
  120.           $message = "This is a multi-part message in MIME format.\n\n" .
  121.              "--{$mime_boundary}\n" .
  122.              "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
  123.              "Content-Transfer-Encoding: 7bit\n\n" .
  124.           $message . "\n\n";
  125.  
  126.           // now we'll process our uploaded files
  127.           foreach($_FILES as $userfile)
  128.           {
  129.              // store the file information to variables for easier access
  130.              $tmp_name = $userfile['tmp_name'];
  131.              $type = $userfile['type'];
  132.              $name = $userfile['name'];
  133.              $size = $userfile['size'];
  134.  
  135.             // echo $tmp_name."\n\n";
  136.  
  137.              // if the upload succeded, the file will exist
  138.              if (file_exists($tmp_name))
  139.              {
  140.  
  141.                if(is_uploaded_file($tmp_name))
  142.                 {
  143.  
  144.                    // open the file for a binary read
  145.                    $file = fopen($tmp_name,'rb');
  146.  
  147.                    // read the file content into a variable
  148.                    $data = fread($file,filesize($tmp_name));
  149.  
  150.                    // close the file
  151.                    fclose($file);
  152.  
  153.                    // now we encode it and split it into acceptable length lines
  154.                    $data = chunk_split(base64_encode($data));
  155.                 }
  156.  
  157.                 // now we'll insert a boundary to indicate we're starting the attachment
  158.                 // we have to specify the content type, file name, and disposition as
  159.                 // an attachment, then add the file content.
  160.                 // NOTE: we don't set another boundary to indicate that the end of the
  161.                 // file has been reached here. we only want one boundary between each file
  162.                 // we'll add the final one after the loop finishes.
  163.                 $message .= "--{$mime_boundary}\n" .
  164.                    "Content-Type: {$type};\n" .
  165.                    " name=\"{$name}\"\n" .
  166.                    "Content-Disposition: attachment;\n" .
  167.                    " filename=\"{$fileatt_name}\"\n" .
  168.                    "Content-Transfer-Encoding: base64\n\n" .
  169.                 $data . "\n\n";
  170.              }
  171.           }
  172.           // here's our closing mime boundary that indicates the last of the message
  173.           $message.="--{$mime_boundary}--\n";
  174.           // now we just send the message
  175.           if (@mail($to, $subject, $message, $headers))
  176.           {
  177.              ?>
  178.                 <script>
  179.  
  180.                       document.location = "submitForm.htm";
  181.                  </script>
  182.               <?}
  183.  
  184.         else
  185.             {
  186.             ?>
  187.                 <script>
  188.                     alert("Message Not Sent, Please Try Again.");
  189.                      document.location = "indexbrowse.htm";
  190.                   </script>
  191.               <?}
  192.        ///////////////////////////////////////////
  193. ?>
  194.  
  195.  
Please advise where I am doing wrong?

You can also view the html form here:
http://www.onlineres.biz/vhdform/test/indexbrowse1.htm


Thanks

Deepak
Dec 1 '08 #1
1 2917
Atli
5,058 Expert 4TB
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.
Dec 3 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

40 posts views Thread by ian | last post: by
3 posts views Thread by marsandys | last post: by
2 posts views Thread by Cimento Cola | last post: by
4 posts views Thread by Max | last post: by
3 posts views Thread by sentiboy | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.