...

View Full Version : Zip Attachments



ACJavascript
10-25-2004, 02:13 AM
Hello,

Heres my problem. I would like to send a ZIP file as an attachment in a php email using the mail() function.

The attachment seems to work but when you download the zip it says its corrupted.

Any ideas??

Heres the code so far:


<?php


$to="email1";
$from="email2";
$subject="Test";
$message="TESTING!";

$headers = "From: $from";

// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
$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";

// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: application/x-zip-compressed;\n" .
" name=\"test.zip\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"test.zip\"\n" .
"Content-Transfer-Encoding: base64\n\n\n\n" .
"--{$mime_boundary}--\n";

// Send the message
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Mail sent!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum