robert_gsfame Posted November 11, 2009 Share Posted November 11, 2009 Below is the code and it didn't work well as file uploaded not in word document, Moreover, i always find the file attached twice (DOUBLE). Another question is that how can i have 2 attachment let say one in word and the other in JPEG format. Please add more code as i'm not familiar with this. Thx in advance $file="upload_file/".$document; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $headers = "From: $from_name<" . $email . ">\n"; $headers .= "Reply-To: <" . $email . ">\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n"; $headers .= "X-Sender: $from_name<" . $email . ">\n"; $headers .= "X-Priority: 1\n"; //1 = Urgent, 3 = Normal $headers .= "Return-Path: <" . $email . ">\n"; $headers .= "This is a multi-part message in MIME format.\n"; $headers .= "------=MIME_BOUNDRY_main_message \n"; $headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n"; $message = "------=MIME_BOUNDRY_message_parts\n"; $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $message .= "Content-Transfer-Encoding: quoted-printable\n"; $message .= "\n"; $message .= "$message\n"; $message .= "\n"; $message .= "------=MIME_BOUNDRY_message_parts--\n"; $message .= "\n"; $message .= "------=MIME_BOUNDRY_main_message\n"; $message .= "Content-Type: application/pdf;\n\tname=\"" . $name . "\"\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment;\n\tfilename=\"" . $name . "\"\n\n"; $message .= $message; //The base64 encoded message $message .= "\n"; $message .= "------=MIME_BOUNDRY_main_message--\n"; $mailto = $recipient_email; $subject = "mymessage"; // send the message mail($mailto, $subject, $message, $headers); Link to comment https://forums.phpfreaks.com/topic/181075-solved-mail-with-attachment-problem/ Share on other sites More sharing options...
robert_gsfame Posted November 11, 2009 Author Share Posted November 11, 2009 okay i've modified the code into below: $to = $email; $from = $from_name; $subject ="Hello world"; $message = "Nice Weather"; $headers = "From: [email protected]"; // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // headers for attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // multipart boundary $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $message .= "--{$mime_boundary}\n"; $file = fopen($files,"rb"); $data = fread($file,filesize($files)); fclose($file); $data = chunk_split(base64_encode($data)); $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$filename\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; $message .= "--{$mime_boundary}\n"; mail($to, $subject, $message, $headers); } THis code works, but this part (From:) i got this [email protected], it should be [email protected] Secondly in which part, should i modify to attach more than one file?? thanx Link to comment https://forums.phpfreaks.com/topic/181075-solved-mail-with-attachment-problem/#findComment-955451 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.