好得很程序员自学网

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

thinkphp结合phpMailer发送邮件 - Thinkphp

thinkphp结合phpMailer发送邮件

一个tinkphp发送邮件功能折腾了我一上午,幸好得到一个网友指导才解决这个问题,在这里我向他表示感谢,好了不多说了把源码贴出来给大家分享一下.

下载phpmailer和邮局文件

将下载的文件解压到ThinkPHP/Extend/Library/ORG下,在控制器中将文件引入:

class  EmailAction  extends  Action  {     public   function  index()    {     if ( $_POST [ 'hid' ]== 'add' )    {     $email = $_POST [ 'email' ];     $title = $_POST [ 'title' ];     $fromname = $_POST [ 'from' ];     $toname = $_POST [ 'to' ];     $myEditor = $_POST [ 'myEditor' ];     $connect = "系统邮件请勿回复" ;    import( 'ORG.Mail.Phpmailer' );     $mail = new  PHPMailer();     $mail ->IsSMTP(); //发送邮件的模式      $mail ->CharSet =  "utf-8" ;  //发送邮件编码      $mail ->Encoding =  "base64" ;     $mail ->IsHTML(true);  //是否使用html格式      $mail ->Host= "smtp.qq.com" ; //邮件服务器      $mail ->SMTPAuth=true; //启用smtp验证功能      $mail ->Username= "826782664@qq.com" ; //帐号      $mail ->Password= "****" ; //密码      $mail ->Port=25; //端口      $mail ->From= "826782664@qq.com" ; //发件人      $mail ->FromName= "$fromname" ; //      $mail ->AddAddress( "$email" , "$toname" );     $mail ->Subject= "$title" ; //邮件标题      $mail ->Body= $myEditor . "<br>" . $connect ; //邮件内容      if (! $mail ->Send())    {       $this ->error( "邮件发送失败" . $mail ->ErrorInfo); exit ;    }     else     {       $this ->success( "邮件发布成功" );    }    } else     {       $this ->display();    }  }  } 

这样就可以实现发送邮件的功能了,小小欢喜一下.

查看更多关于thinkphp结合phpMailer发送邮件 - Thinkphp的详细内容...

  阅读:84次