加入收藏 | 设为首页 | 会员中心 | 我要投稿 拼字网 - 核心网 (https://www.hexinwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php mail邮件发送带附件功能

发布时间:2022-01-21 03:23:45 所属栏目:PHP教程 来源:互联网
导读:$pdfname=test.pdf; $email=test@test.com; $text = 您好,附件中是您需要的pdf文件。请点击下载。bra href=http://www.Cuoxin.comwww.Cuoxin.com/a; //文本内容 $text = base64_encode($text); //用base64方法把它编码 $text = chunk_split($text); //把这
  $pdfname="test.pdf";
  $email="test@test.com";
  $text = "您好,附件中是您需要的pdf文件。请点击下载。<br><a href=http://www.Cuoxin.com>www.Cuoxin.com</a>";         //文本内容
  $text = base64_encode($text);     //用base64方法把它编码  
  $text = chunk_split($text);     //把这个长字符串切成由每行76个字符组成的小块
  $subject = $pdfname;         //标题  
  $from = "admin@Cuoxin.com";     //发送者  
  $to = $email;     //接受者
  //附件  
  // 定义分界线  
  $boundary = "nextpart_".uniqid("");  
  $boundary2 = "nextpart_".uniqid("");  
  $headers = "to: $torn";
  $headers .= "from: $fromrn";  
  $headers .="mime-version: 1.0rn";
  $headers .= "content-type: multipart/mixed;  
              boundary="----=_$boundary"rn";
  $read=file_get_contents($pdfname);
  $read = base64_encode($read);     //用base64方法把它编码  
  $read = chunk_split($read);     //把这个长字符串切成由每行76个字符组成的小块
  //现在我们可以建立邮件的主体  
  $body = "this is a multi-part message in mime format.
  ------=_$boundary
  content-type: multipart/alternative;
      boundary="----=_$boundary2";
  ------=_$boundary2
  content-type: text/html;
      charset="gbk"
  content-transfer-encoding: base64
  $text
  ------=_$boundary2--
  ------=_$boundary
  content-type: application/octet-stream;
      charset="gbk";
      name="$pdfname"
  content-disposition: attachment; filename="$pdfname"
  content-transfer-encoding: base64
  $read
  -------=_$boundary--";
  if(mail($to, $subject,$body,$headers))  
     echo "您需要的pdf文件(".$pdfname.")已经发往您的邮箱:".$to."。<br>请查收。";  
  else  
     echo "抱歉,发送失败了。<br>"; 

(编辑:拼字网 - 核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!