好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

php mail邮件发送带附件功能

$pdfname = "test.pdf" ;  $email = "test@test.com" ;  $text  =  "您好,附件中是您需要的pdf文件。请点击下载。<br><a href=http://www.phpfensi.com>www.phpfensi.com</a>" ;         //文本内容  $text  =  base64_encode ( $text );      //用base64方法把它编码    $text  =  chunk_split ( $text );      //把这个长字符串切成由每行76个字符组成的小块   $subject  =  $pdfname ;          //标题    $from  =  "admin@phpfensi.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>" ;  

查看更多关于php mail邮件发送带附件功能 - php高级应用的详细内容...

  阅读:66次