php - send a email with attachment(Problem is the file size is 0k) -
dear friends, have problem file attachment, using email functionality attachment project, attached file.xls mail, in mail cant file values, showing 0k. file in local having datas, not working while run email functionality, attachment have 0k size, can me please... code below....
$filename = "test.xls"; $path = $_server['document_root']."/path/to/documents/"; $file = $path.$filename; $to = "example@test.com"; $subject = 'repairs list report'; $message = "please find attachment file repairs list of last week..."; //strip_tags($_post['message']); $attachment = chunk_split(base64_encode(file_get_contents($file))); //$filename = $_files['file']['name']; $boundary =md5(date('r', time())); $headers = "from: test@example.com\r\nreply-to: example@test.com"; $headers .= "mime-version: 1.0"; $message="this multi-part message in mime format. --_1_$boundary content-type: multipart/alternative; boundary=\"_2_$boundary\" --_2_$boundary content-type: text/plain; charset=\"iso-8859-1\" content-transfer-encoding: 7bit $message --_2_$boundary-- --_1_$boundary content-type: application/vnd.ms-excel; name=\"$filename\" content-transfer-encoding: base64 content-disposition: attachment $attachment --_1_$boundary--"; mail($to, $subject, $message, $headers);
first thing do, output $message see if indeed generate valid mime-formatted email. can't certain, looking @ code.. 1 thing:
$headers = "from: test@example.com\r\nreply-to: example@test.com"; $headers.= "mime-version: 1.0";
should be:
$headers = "from: test@example.com\r\nreply-to: example@test.com\r\n"; $headers.= "mime-version: 1.0";
well forgot put linebreaks in message:
$body ="this multi-part message in mime format. (preamble)\r\n"; $body.="--_1_$boundary\r\n"; $body.="content-type: multipart/alternative; boundary=\"_2_$boundary\"\r\n"; $body.="--_2_$boundary\r\n"; $body.="content-type: text/plain; charset=\"iso-8859-1\"\r\n"; $body.="content-transfer-encoding: 7bit\r\n"; $body.="\r\n"; $body.="$message\r\n"; $body.="--_2_$boundary--\r\n"; $body.="--_1_$boundary\r\n"; $body.="content-type: application/vnd.ms-excel; name=\"$filename\"\r\n"; $body.="content-transfer-encoding: base64\r\n"; $body.="content-disposition: attachment\r\n"; $body.="\r\n"; $body.="$attachment\r\n"; $body.="--_1_$boundary--"; mail($to, $subject, $body, $headers);
i'm not sure if missed can start this. lastly can use class made, omime, simplifies making mime emails.
Comments
Post a Comment