1.Here i am trying to send my jpg image file as attachment to mail using php mail() function.
2.My mail attachment is sending fine with word document(.doc as attachment).But,throws errorwhen i try to send .jpg as attachment.The code i used:
<?php
/*If there is no error, send the 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 a 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, we start the body!*/
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "Check out the 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 for Brochure form";
$msg = $_POST['username'] . ",\n\nThank you for your 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 the 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 to receive mail with the body content("Check out the attachment") and having attachment as image.jpg with 0k(no image is opened).
5.please help.thanks in advance.Its urgent.