Jump to content

MIME Email Attachments Received Corrupted/Incomplete


atchua

Recommended Posts

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
If you can install this package, it will make life much easier: http://pear.php.net/package/Mail_Mime

Or 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.
just to clarify, and by the way thanks for the quick reply

do 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.