The email sends fine, and the email has an attachment, but the attachment is always corrupted in some way (image is broken, zip file wont open, etc.)
Also, I believe the MIME encoding is fine, but it would be great if someone took a second look at that. Thanks alot.
Jabbamonkey
THE CODE...
======================================
Code: Select all
$file_name; // Name of the file on the server, determined before
$pathonserver = "/usr/home/v1/x1234567/html/upload/";
$fileonserver = $pathonserver."".$file_name;
$file_type = $thetype; // Determined before
$email_from = "Someone"; // Who the email is from
$email_subject = "Email Attachment from Server";
$email_message = "Testing Attachment from Server";
$email_to = "person@domainname.com";
// #### POSSIBLE PROBLEM ####
$file = fopen($fileonserver,'rb');
$data = fread($file,filesize($fileonserver));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==_=_Multipart_Boundary_x{$semi_rand}x";
$headers = "From: " . $email_from .
"\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary="{$mime_boundary}"";
$data = chunk_split(base64_encode($data));
$email_message = "--{$mime_boundary}\n" .
"Content-Type: text/html;\n" .
" charset="iso-8859-1"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: {$file_type};\n" .
" name="{$file_name}"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: attachment;\n" .
" filename="{$file_name}"\n" .
// $data . "\n\n" .
"\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);