为了账号安全,请及时绑定邮箱和手机立即绑定

使用PHP Mail()发送附件?

使用PHP Mail()发送附件?

PHP
莫回无 2019-05-27 15:38:14
使用PHP Mail()发送附件?我需要发送带有邮件的pdf,这可能吗?$to = "xxx";$subject = "Subject" ;$message = 'Example message with <b>html</b>';$headers  = 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";$headers .= 'From: xxx <xxx>' . "\r\n";mail($to,$subject,$message,$headers);我错过了什么?
查看完整描述

3 回答

?
跃然一笑

TA贡献1826条经验 获得超6个赞

对于PHP 5.5.27安全更新


$file = $path.$filename;

$content = file_get_contents( $file);

$content = chunk_split(base64_encode($content));

$uid = md5(uniqid(time()));

$name = basename($file);


// header

$header = "From: ".$from_name." <".$from_mail.">\r\n";

$header .= "Reply-To: ".$replyto."\r\n";

$header .= "MIME-Version: 1.0\r\n";

$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";


// message & attachment

$nmessage = "--".$uid."\r\n";

$nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n";

$nmessage .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

$nmessage .= $message."\r\n\r\n";

$nmessage .= "--".$uid."\r\n";

$nmessage .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";

$nmessage .= "Content-Transfer-Encoding: base64\r\n";

$nmessage .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";

$nmessage .= $content."\r\n\r\n";

$nmessage .= "--".$uid."--";


if (mail($mailto, $subject, $nmessage, $header)) {

    return true; // Or do something here

} else {

  return false;

}


查看完整回答
反对 回复 2019-05-27
  • 3 回答
  • 0 关注
  • 1685 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信