c_pattle Posted June 2, 2010 Share Posted June 2, 2010 I have a script that sends email attachments to my inbox and when I tested it it works fine. However when I try to send it to someone else's inbox the attachments appear empty and are corrupt. Surely if it worked with one email address it should work with another? I've copied my php code below to see if anyone can spot any errors. $to = "[email protected]"; $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 = ""; } } Link to comment https://forums.phpfreaks.com/topic/203657-strange-email-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.