I've got a loop that loops through attachments and then sends them by email. When I sent it to my address the attachments got there fine. However when I sent it to a different address the attachments got there but were all empty as if they hadn't been encoded properly. Do you think this could be problem with my script or a problem with the different email addresses? I've copied my script below.
Code: Select all
<?php
$to = "alex@colourbrush.co.uk";
$subject = "You have been sent some content by " . $_REQUEST['order_company_name'];
$email = $_REQUEST['order_email'] ;
foreach ($_FILES['att']['error'] as $key => $error) {
if (UPLOAD_ERR_OK === $error) {
$att_path = $_FILES['att']['tmp_name'][$key];
$att_name = $_FILES['att']['name'][$key];
$att_size = $_FILES['att']['size'][$key];
$att_type = $_FILES['att']['type'][$key];
$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));
$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 "<p>Thank you. Your attachment was sent successfully</p>"; }
else
{print "<p>Sorry. We encountered an error sending your mail</p>"; }
$msg = "";
$headers = "";
}
}
?>