Hello,
I am using the following code to attach a .png file to an email.
When I send the email to my test account at yahoo.com. It shows
an email paperclip icon and the email has a file size indicating the
file was attached.
I just can't get to it at all, so something is not right with this.
I would appreciate it if someone with more knowledge can tell me
what is messed up. (See function below).
function mail_attached($to, $from, $subject, $message, $filename, $headers = '') {
$unique_sep = md5(uniqid(time()));
$headers .= "From: $from\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$unique_sep\";\r\n\r\n";
$headers .= "This is an MIME encoded message.\r\n";
$headers .= "charset=\"iso-8859-1\"\nContent-Transfer-Encoding:7bit\n\n";
$headers .= "--$unique_sep\r\n";
$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$headers .= "Content-Transfer-Encoding: 7bit\n\n";
$headers .= $message."\r\n\r\n";
$headers .= "--$unique_sep--\r\n";
if(file_exists($filename)) {
$headers .= "--$unique_sep\r\n";
$headers .= "Content-Type: image/png; name='".$filename."'\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment\r\n\r\n";
$filedata = implode(file($filename), '');
$headers .= chunk_split(base64_encode(file_get_contents($filename)));
}
$headers .= "--$unique_sep--";
if(!mail($to, $subject, $message, $headers)) {
echo "Error: mail() function failed!<BR>";
}
} / End of mail_attached() function /