<?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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.