Hi,
I wrote a php script to email a jpg file. This script does mail the jpg file but when i try to open the jpg file with an image viewer the image does not load. I think my image is corrupted or in a different format. Please tell me how to solve this problem.
Here is my coding
<?
$mail_boundary = md5(uniqid(time()));
$mail_headers ="From:chamalsl@yahoo.com\r\n";
$mail_headers .= "MIME-Version:1.0\r\n";
$mail_headers .="Content-type:multipart/mixed;boundary=\"$mail_boundary\"";
$mail_headers .="\r\n\r\n";
$mail_headers .="This is a multipart message in mime format";
$mail_headers .="\r\n\r\n";
//Reading the file
$userfile = "bruce.jpg";
$fp = fopen($userfile,"r");
$file = fread($fp,filesize($userfile));
$file =chunk_split(base64_encode($file));
//Creating the mail body
$mail_body = "--$mail_boundary\n";
$mail_body .="Content-type:text/plain;charset=us-ascii\r\n";
$mail_body .="Content-transfer-encoding:7bit\r\n\r\n";
$mail_body .="Email sent using Sinhalaya com\r\n";
$mail_body .="--$mail_boundary\r\n";
$filename = basename($userfile);
$mail_body .="Content-type:image\jpeg;name=$filename\r\n";
$mail_body .="Content_transfer-encoding:base64\r\n";
$mail_body .=$file."\r\n\r\n";
$mail_body .="--$mail_boundary--";
mail("chamalsl@yahoo.com","Email from sinhalaya",$mail_body,$mail_headers);
?>
Thanks,
Chamal.