I've been trying to get this script to work for ages but having no luck. I have an attachment for which I have shown below
<form method="post" action="order_success2.php" enctype="multipart/form-data">
<ul>
<li><input type="file" name="att[]" size="26" /></li>
<li><input type="file" name="att[]" size="26" /></li>
<li><input type="submit" name="submit" value="Submit!" /></li>
</ul>
</form>
What I'm trying to achieve is to be able to send more than one attachment with an email. At the moment I can only get one to work. Can anyone help pleaseeeeeee?
This is the script I'm using
<?php
$to = "someone@gmail.com";
foreach($_FILES['att'] as $key => $value){
$att = $value['att'];
$att_path = $value['att']['tmp_name'];
$att_name = $value['att']['name'];
$att_size = $value['att']['size'];
$att_type = $value['att']['type'];
$fp = fopen( $att_path, "rb");
$file = fread( $fp, $att_size );
fclose ($fp);
$num = md5(time());
$str = "==multipart_Boundary_x{$num}x";
$file = chunk_split(base64_encode($file));
$subject = "You have been sent some content by " . $_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}";
$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"; }
}
?>
Thanks