1.这里我正在尝试使用 php mail() 函数将我的 jpg 图像文件作为附件发送到邮件。
2.我的邮件附件与word文档(.doc作为附件)一起发送很好。但是,当我尝试将.jpg作为附件发送时抛出错误。我使用的代码:
<?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.错误被提出为:
警告:file_get_contents(image.jpg) [function.file-get-contents]:无法
打开流:第 48 行的 footer.php 中没有此类文件或目录
4.我曾经收到带有正文内容的邮件(“检查附件”),附件为image.jpg,0k(没有打开图像)。
5.please help.thanks提前。它的紧急。