atchua Posted November 13, 2006 Share Posted November 13, 2006 I got the following script from another site http://forums.devshed.com/php-development-5/help-php-mime-email-attachment-problems-112815.html:$headers .= "\r\nMIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; $email_message = "This is a multi-part message in MIME format.\r\n\r\n" . "--{$mime_boundary}\r\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n"; $email_message .= "\r\n$email_txt \r\n"; $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\r\n" . "Content-Type: {$fileatt_type};\r\n" . " name=\"{$fileatt_name}\"\r\n" . //"Content-Disposition: attachment;\r\n" . //" filename=\"{$fileatt_name}\"\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n" . $data . "\r\n\r\n" . "--{$mime_boundary}--\r\n"; // actual sending of the email $ok = @mail($email_to, $email_subject, $email_message, $headers);running it the first time had errors and i still have to include \r character for every \n in the header variable (as posted above). after that, it had no problems sending the file/attachment. however, upon checking the contents attachment, it was incomplete and cut short.i just want to ask if anyone experienced the same thing and what did you do to fix the problem of incomplete/corrupted file attachments.Thanks in advance Quote Link to comment Share on other sites More sharing options...
btherl Posted November 13, 2006 Share Posted November 13, 2006 If you can install this package, it will make life much easier: http://pear.php.net/package/Mail_MimeOr it may already be installed.One thing you might want to check is that chunk_split() is producing the correct linefeeds. It may be producing \n only.If it is, you'll need to run $data through [code=php:0]str_replace("\n","\r\n", $data)[/code]. That could easily cause truncated messages due to line length limits. Quote Link to comment Share on other sites More sharing options...
atchua Posted November 13, 2006 Author Share Posted November 13, 2006 just to clarify, and by the way thanks for the quick replydo i perform the str_replace("\n","\r\n", $data) before or after i perform the chunk_split() function?is it possible that php versions issues might cause the corruption as well? because when i run this script on my server, it works fine with complete and not corrupted file attachments. But when i transfer the script to another server, the file attachment was corrupted. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.