0
<?php
$to="sreedevs.arun@gmail.com";
$subject="bad boy";
$message="message";
$attachment="image.jpg";
$attachment_MIME_type="image/jpeg";
$handle=fopen ($attachment,"rb");
$data=fread ($handle, filesize($attachment));
fclose ($handle);
$boundary="---Multipart_Boundary----";
$headers="\nMIME-Version: 1.0\n".
"Content-Type: multipart/mixed;\n".
" boundary=\"".$boundary."\"";
$data=chunk_split(base64_encode($data));
$text="--".$boundary."\n";
"Content-Type:text/plain\nContent-Transfer-Encoding: 7bit\n\n".
$message."\n\n--".$boundary."\n".
"Content-Type:".$attachment_MIME_type.";\n name=\"".
$attachment."\"\nContent-Transfer-Encoding:base64\n\n".
$data."\n\n--".$boundary."--\n";
$result=@mail($to,$subject,$text,$headers);
if($result)
{
echo "the mail was sent";
}
else
{
echo "the mail was not sent";
}
?>

output is------

Warning: fopen(image.jpg) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\mail\mail.php on line 9

Warning: filesize() [function.filesize]: stat failed for image.jpg in C:\xampp\htdocs\mail\mail.php on line 10

Warning: fread() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\mail\mail.php on line 10

Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\mail\mail.php on line 11
the mail was not sent

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by serverack
0

I advise you to use PEAR package.
Its fantastic and easy, because I had same problem like you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.