首页 > 开发 > PHP > 正文

thinkphp使用phpmailer发送邮件的方法

2024-05-04 22:17:20
字体:
来源:转载
供稿:网友

本文实例讲述了thinkphp使用phpmailer发送邮件的方法。分享给大家供大家参考。具体分析如下:

phpmailer发送邮件是php开发者首选的一个邮件发送插件了,下面我来介绍怎么集成phpmailer到thinkphp框架了,感兴趣的朋友可以参考一下。

phpmailer发送邮件功能很强大,今天真正的体验一下,这里先简单说一下配置,本人是在thinkphp中使用的.

配置步骤:

1.后台配置发送邮件类,位置admin/common/common.php中,代码如下:
代码如下:function sendmail($tomail,$title,$content) 

/*邮件设置信息*/ 
        $email_set = C('EMAIL_SET'); 
        Vendor('phpmailer.class#phpmailer'); 
        Vendor("phpmailer.class#smtp"); //可选,否则会在class.phpmailer.php中包含 
         
        $mail = new PHPMailer(true); //实例化PHPMailer类,true表示出现错误时抛出异常 
         
        $mail->IsSMTP(); // 使用SMTP 
          $mail->CharSet ="UTF-8";//设定邮件编码 
          $mail->Host       = $email_set['Host']; // SMTP server 
          $mail->SMTPDebug  = 1;                     // 启用SMTP调试 1 = errors  2 =  messages 
          $mail->SMTPAuth   = true;                  // 服务器需要验证 
          $mail->Port       = $email_set['port'];                    // 设置端口 
         // $mail->SMTPSecure = "ssl";      
            /* 
            $mail->SMTPSecure = "ssl";                  
            $mail->Host       = "smtp.gmail.com";      
            $mail->Port       = 465;                   

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表