471,086 Members | 802 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

sending mail attachment in php

26
Hi all,

I got problem in sending email with image file attached. the problem is that i can't see the image, apart from that i also try to attach a txt file and it gave me no luck. the txt file in the mail attachment is empty.

Tha following is my code, i hope somebody can help me out.
[PHP]
$file="Globe.gif";
$fp = fopen($file,"r");
$fcontent = fread($fp ,filesize($file));


fclose($fp);
$content = chunk_split(base64_encode($fcontent));

echo $fcontent;
$sep = md5(time());

$name = basename($file);

$headers = "From:kencana@kesuma.com\r\n";
$headers .= "Reply-To:kencana@kesuma.com\r\n";

$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=$sep";


$body = "--$sep\n";
$body .= "Content-Type: text/plain;\n";
$body .= "Content-Transfer-Encoding: 8bit\n\n";
$body .= "Hello There!\n";
$body .= "--$sep\n";
$body .= "Content-Type: image/gif; name=\"$file\"\n";
$body .= "Content-Transfer-Encoding: base64;\n";
$body .= "Content-Disposition: attachment; filename=\"$file\"\n";
$body .= "$content\n";
$body .= "--$sep--";

mail("kencana@kesuma.com","This is the subject",$body, $headers);
[/PHP]

Thank you very much

Regards,
Kencana
Mar 23 '07 #1
0 1595

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Dragos Marian Barbu | last post: by
6 posts views Thread by Anuradha | last post: by
3 posts views Thread by dnuos | last post: by
maliksleo
1 post views Thread by maliksleo | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.