Image attachment in php fails to be sent?
<p>The code below works perfectly well when I change the attached file to an html file,but when I change the attached file to an image i.e. screenshot.png it fails to send the message.</p>

<pre><code>&lt;?php
    $file_path = "screenshot.png"; // server path where file is placed
    $file_path_type = "image/png"; // File Type
    $file_path_name = "screenshot.png"; // this file name will be used at reciever end 

    $from = "xyz@gmail.com"; // E-mail address of sender
    $to = "abc@gmail.com"; // E-mail address of reciever
    $subject = "Please check the Attachment."; // Subject of email
    $message = "This is the message body.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Thank You!&amp;lt;br&amp;gt;&amp;lt;a href='http://7tech.co.in'&amp;gt;7tech.co.in Team&amp;lt;/a&amp;gt;"; 

    $headers = "From: ".$from; 

    $file = fopen($file_path,'rb');
    $data = fread($file,filesize($file_path));
    fclose($file); 

    $rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$rand}x"; 

    $headers .= "\nMIME-Version: 1.0\n" .
    "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mime_boundary}\""; 

    $message .= "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary}\n" .
    "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $message .= "\n\n"; 

    $data = chunk_split(base64_encode($data)); 

    $message .= "--{$mime_boundary}\n" .
    "Content-Type: {$file_path_type};\n" .
    " name=\"{$file_path_name}\"\n" .
    "Content-Disposition: attachment;\n" .
    " filename=\"{$file_path_name}\"\n" .
    "Content-Transfer-Encoding: base64\n\n" .
    $data .= "\n\n" .
    "--{$mime_boundary}--\n";  

    if(@mail($to, $subject, $message, $headers)) {
    echo "File send!";

    } else {
    echo 'Failed';
    }
    ?&gt;
</code></pre>

<p>Can you guys point out the error.I've tried to cahnge content type too at 1-2 places but it wasn't working.Am I missing anything?</p>
