php专区

 首页 > php专区 > PHP应用 > 常用功能 > php mail邮件发送带附件功能 - php高级应用

php mail邮件发送带附件功能 - php高级应用

分享到:
【字体:
导读:
          $pdfname=test pdf;$email=test@test com;$text=您好,附件中是您需要的pdf文件。请点击下载。brahref=http: www phpfensi comww...

php mail邮件发送带附件功能

  1. $pdfname="test.pdf"
  2. $email="test@test.com"
  3. $text = "您好,附件中是您需要的pdf文件。请点击下载。
    www.phpfensi.com"
    ;         //文本内容 
  4. $text = base64_encode($text);     //用base64方法把它编码  
  5. $text = chunk_split($text);     //把这个长字符串切成由每行76个字符组成的小块 
  6. $subject = $pdfname;         //标题  
  7. $from = "admin@phpfensi.com";     //发送者  
  8. $to = $email;     //接受者 
  9. //附件  
  10. // 定义分界线  
  11. $boundary = "nextpart_".uniqid("");  
  12. $boundary2 = "nextpart_".uniqid("");  
  13. $headers = "to: $torn"
  14. $headers .= "from: $fromrn";  
  15. $headers .="mime-version: 1.0rn"
  16. $headers .= "content-type: multipart/mixed;  
  17.             boundary="----=_$boundary"rn"; 
  18. $read=file_get_contents($pdfname); 
  19. $read = base64_encode($read);     //用base64方法把它编码  
  20. $read = chunk_split($read);     //把这个长字符串切成由每行76个字符组成的小块 
  21. //现在我们可以建立邮件的主体  
  22. $body = "this is a multi-part message in mime format. 
  23. ------=_$boundary 
  24. content-type: multipart/alternative; 
  25.     boundary="----=_$boundary2"
  26. ------=_$boundary2 
  27. content-type: text/html; 
  28.     charset="gbk" 
  29. content-transfer-encoding: base64 
  30. $text 
  31. ------=_$boundary2-- 
  32. ------=_$boundary 
  33. content-type: application/octet-stream; 
  34.     charset="gbk"
  35.     name="$pdfname" 
  36. content-disposition: attachment; filename="$pdfname" 
  37. content-transfer-encoding: base64 
  38. $read 
  39. -------=_$boundary--"; 
  40. if(mail($to$subject,$body,$headers))  
  41.    echo "您需要的pdf文件(".$pdfname.")已经发往您的邮箱:".$to."。
    请查收。"
    ;  
  42. else  
  43.    echo "抱歉,发送失败了。
    "
    ; 
分享到:
php 使用qmail发送邮件实现代码 - php高...
php 使用qmail发送邮件实现代码 以前都是利用mail函数或php教程ermail进行邮件发送,今天看这款利用qmail进行邮件发送,写法非常简单,是一款不错的工具. function send_check_mail($email, $subject,$uid,$buffer)  {      echo "hello";   $command = "/var/qmail/bi...
利用 PHPMailer发送邮件(可发送 HTML内容...
利用 PHPMailer发送邮件(可发送 HTML内容,图片,附件) 利用phpmailer发送邮件(可发送 html内容,图片,附件),phpmailer是一个用于发送电子邮件的php类,他比php自带的函数mail强多了,phpmailer可以到官方下载。 下面来看一个只发送文本的实例: */  require("class.phpmailer.php")...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……