Hello,
I am using this script to send mime messages with attachment. It works fine except that the attachments that are sent with the mail are just empty files.
The strange thing is that when I receive this email it shows the size of the attachment (which is larger than 0kb). ???
I doubt that it has something to do with my script. I've tried others and they have the same problem. I've also tried different mailservers; same problem.
I've tested my mail program and it's working fine.
Maybe it could be some setting in php ini?
<?php
ini_set (SMTP, smtp.example.com);
ini_set (smtp, 25);
$fileatt = "background.gif"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "background.gif"; // Filename that will be used for the file as the attachment
$email_from = "my_email@example.com"; // Who the email is from
$email_subject = "test"; // The Subject of the email
$email_txt = "testmessage"; // Message that the email has in it
$email_to = "your_email@example.com"; // Who the email is too
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$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" .
"--{$mime_boundary}\r\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\r\n" .
"Content-Transfer-Encoding: 7bit\r\n" .
$email_message . "\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;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\r\n" .
$data . "\r\n" .
"--{$mime_boundary}--\r\n";
$ok = mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo "<font face=verdana size=2>The file was successfully sent!</font>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>