Home  >  Article  >  php教程  >  phpmailer发送邮件,可以带附件

phpmailer发送邮件,可以带附件

WBOY
WBOYOriginal
2016-06-21 08:48:591052browse

实例

 

require_once ('PHPMailer/class.phpmailer.php'); //引入phpmailer文件

require_once ('PHPMailer/class.smtp.php');

 

     $mail=new PHPMailer(); //实例化phpmailer类

     $mail->IsSMTP();

     $mail->CharSet='UTF-8';

     $mail->AddAddress(123@163.com); //收件人邮箱

     $mail->Body=$content; //发件内容

     $mail->From=from@163.com; //发件人邮箱from@163.com 

 

     $mail->FromName="zjsupport";  //发件人的名字

     $mail->Subject="title";    //邮件标题

     $mail->Host="smtp.163.com"; //smtp服务器 

     $mail->SMTPAuth=true;  //开启smtp服务

     $mail->IsHTML(true); 

     //发送附件

     $mail->AddAttachment(path,name); //path是附件的保存路径 name是附件的名字

 

                                                                       //可以上传多个附件,一模一样复制  $mail->AddAttachment(path,name); 代码就行

 

 

     $mail->Username="from@163.com ";//发件人邮箱

     $mail->Password="123456";//发件人邮箱密码

     

     if($mail->Send()){  //判断邮件是否发送成功

      echo "success";

     }else{  

      $email_error=$email_error.";".$val;  //若不成功将发送失败的邮箱存入字符窜

     }

     

     if($email_error==""){

      echo "email_success";

     }else{

      echo $email_error;

     }



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn