Jump to content

How to send two attachment


c_pattle

Recommended Posts

I have the following code which sends an attachment to my inbox.  However I want to be able to send two attachments.  Does anyone know how this is done?  I tried to just repeat all the code changing "att" (name of input) to "att2" but it still only sent the first one.  Thanks for any help. 

 

<?php 

$to = "[email protected]"; 

$att = $_FILES['att'];
$att_path = $_FILES['att']['tmp_name'];
$att_name = $_FILES['att']['name'];
$att_size = $_FILES['att']['size'];
$att_type = $_FILES['att']['type'];

$att2 = $_FILES['att2'];
$att2_path = $_FILES['att2']['tmp_name'];
$att2_name = $_FILES['att2']['name'];
$att2_size = $_FILES['att2']['size'];
$att2_type = $_FILES['att2']['type'];

$fp = fopen( $att_path, "rb");
$file = fread( $fp, $att_size );
fclose ($fp);

$fp2 = fopen( $att2_path, "rb");
$file2 = fread( $fp2, $att2_size );
fclose ($fp2);

$num = md5(time());
$str = "==multipart_Boundary_x{$num}x";

$file = chunk_split(base64_encode($file));

$subject = "You have a new order from " . $_REQUEST['order_company_name']; 

$email = $_REQUEST['order_email'] ; 
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/mixed;";
$headers .= "boundary=\"{$str}\"\r\n";
$headers .= "From: $email"; 

$msg .= "This is a multi-part message in MIME format\r\n\n";
$msg .= "--{$str}\r\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding: 8bit\r\n";
$msg .= "--{$str}\r\n";

$msg .= "Content-Type: {$att_type}; ";
$msg .= "name=\"{$att_name}\"\r\n";
$msg .= "Content-Disposition: attachment; ";
$msg .= "filename =\"{$att_name}\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "$file\r\n\n";
$msg .= "--{$str}";

$msg .= "Content-Type: {$att2_type}; ";
$msg .= "name=\"{$att2_name}\"\r\n";
$msg .= "Content-Disposition: attachment; ";
$msg .= "filename =\"{$att2_name}\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "$file2\r\n\n";
$msg .= "--{$str}";

$sent = mail($to, $subject, $msg, $headers) ; 
if($sent) 
{print "Thank you.  Your order was sent successfully"; }
else 
{print "Sorry.  We encountered an error sending your mail"; }
?>

Link to comment
https://forums.phpfreaks.com/topic/203070-how-to-send-two-attachment/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.