wordpress - Warning: file_get_contents(image.jpg) [function.file-get-contents]: failed to open stream: No such file or directory in php -


1.here trying send jpg image file attachment mail using php mail() function.

2.my mail attachment sending fine word document(.doc attachment).but,throws errorwhen try send .jpg attachment.the code used:

<?php /*if there no error, send email*/ if(isset($_post['submit-button-name'])) { $uname=$_post['uname']; $to = $_post['mailid']; $mobileno=$_post['mobile']; $location=$_post['location']; $from = "urname <urname@domainname.com>"; $subject = $_post['uname']." testing"; $separator = md5(time()); /* carriage return type (we use php end of line constant)*/ $eol = php_eol; /*attachment name*/ $filename = "image.jpg"; $attachment = chunk_split(base64_encode(file_get_contents('image.jpg'))); /*main header*/ $headers = "from: ".$from.$eol; $headers .= "mime-version: 1.0".$eol; $headers .= "content-type: multipart/mixed; boundary=\"".$separator."\""; /*no more headers after this, start body!*/ $body = "--".$separator.$eol; $body .= "content-transfer-encoding: 7bit".$eol.$eol; $body .= "check out attachment.".$eol; /*message*/ $body .= "--".$separator.$eol; $body .= "content-type: text/html; charset=\"iso-8859-1\"".$eol; $body .= "content-transfer-encoding: 8bit".$eol.$eol; $body .= $message.$eol; /*attachment*/ $body .= "--".$separator.$eol; $body .= "content-type: image/jpg; name=\"".$filename."\"".$eol; $body .= "content-transfer-encoding: base64".$eol; $body .= "content-disposition: attachment; file=\"".$filename."\"".$eol.$eol; $body .= $attachment.$eol; $body .= "--".$separator."--"; /*send message*/ if (mail($to, $subject, $body, $headers)) { $mail_sent=true; echo "<font color='white'>mail sent</font>"; $frm="urname@domainname.com"; $subj="acknowledgement mail brochure form"; $msg = $_post['username'] . ",\n\nthank recent enquiry."; $body = "name: ".$_post['uname'] ."\n\nemail: ".$_post['mailid'] ."\n\nmobile: ".$_post['mobile'] ."\n\nlocation: ".$_post['location']; $headers = 'from: '.'careers@domainname.com'; mail($frm,$subj,$body,$headers); } else { $mail_sent=false; } if($mail_sent == true) { /*to clear post values*/ $uname=""; $to=""; $mobileno=""; $location=""; } else{ echo "error,mail not sent"; } } ?> 

3.error being raised as:

warning: file_get_contents(image.jpg) [function.file-get-contents]: failed to
open stream: no such file or directory in footer.php on line 48

4.i used receive mail body content("check out attachment") , having attachment image.jpg 0k(no image opened).

5.please help.thanks in advance.its urgent.

i thought content type jpeg not jpg.

content-type: image/jpeg;

in section add attachments.

also lines:

$body .= "content-disposition: attachment; file=\"".$filename."\"".$eol.$eol;

$body .= "--".$separator."--";

probably should be:

$body .= "content-disposition: attachment;".$eol.$eol;

$body .= "--".$separator."--".$eol;


Comments