PHP使用mail发送带附件邮件的程序

        echo '<p>......开始发送邮件........<br>';
        $from = 'xxx@hazy.allcx.com';
        $to   = 'xxx@qq.com';
        $boundary= md5(uniqid(""));
       
       
        $headers   =   "From:   ".$from. "\n";
        $headers   .= "Mime-Version:   1.0\nContent-Type:   multipart/mixed;  boundary=\"$boundary\"\n\nThis   is   a   multi-part   message   in   MIME   format.\n\n";
        $headers   .=   "--$boundary\n"; 
        $headers   .=   "Content-Type:   text/html\n\n ";
        $headers   .=   "\n xxxxx  \n\n"; 

        //另附zip文件
        $fd   =   fopen($zipname,   "r")   or   die("unable   to   open   file   $zipname"); 
        $contents   =   chunk_split(base64_encode(fread($fd,filesize($zipname)))); 
        fclose($fd);
        $headers   .=   "--$boundary\n";
        $headers   .=   "Content-Type:   application/octet-stream;  name=\"".$zipname."\"\n";
        $headers   .=   "Content-Transfer-Encoding:   base64\n";
        $headers   .=   "Content-Disposition:   attachment;   filename=\"".$zipname."\"\n\n ";
        $headers   .=   $contents. "\n\n";
        //*/
        $headers   .=   "--$boundary--\n\n";
        if(mail($to, $zipname.'-'.date('Y-m-d'), '', $headers)) echo '发送邮件成功';
        exit;

就这几行代码,网上偏偏要搞成一个类,害老子找了一天。而且文章一大抄,没几个能用的。上面这个程序本人正在使用中。
300*300
  • 没有相关文章
  • 没有评论
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.00607 秒