用户
 找回密码
 入住 CI 中国社区
搜索
12
返回列表 发新帖
楼主: 裕波?忘记
收起左侧

[讨论/交流] 在CI中集成phpmailer,方便使用SMTP发送邮件

[复制链接]
发表于 2013-7-8 22:28:42 | 显示全部楼层
顶学习了.
发表于 2013-7-8 22:29:05 | 显示全部楼层
不过貌似应该放在helper类中,这样是不是更好哇?
发表于 2013-7-8 22:47:20 | 显示全部楼层
我完整的修改了下,是163的.
PHP复制代码
 
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
 
 
class Mailer {
 
 
 
    var $mail;
 
 
 
    public function __construct()
 
    {
 
        require_once('PHPMailer_5.2.2/class.phpmailer.php');
 
 
 
        // the true param means it will throw exceptions on errors, which we need to catch
 
        $this->mail = new PHPMailer(true);
 
 
 
        $this->mail->IsSMTP(); // telling the class to use SMTP
 
 
 
        $this->mail->CharSet = "utf-8";                  // 一定要設定 CharSet 才能正確處理中文
 
      //  $this->mail->SMTPDebug  = 0;                     // enables SMTP debug information
 
        $this->mail->SMTPAuth   = true;                  // enable SMTP authentication
 
      //  $this->mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
 
        $this->mail->Host       = "smtp.163.com";      // sets 163 as the SMTP server
 
        //$this->mail->Port       = 465;                   // set the SMTP port for the 163 server
 
        $this->mail->Username   = "xxxxxx@163.com";// 163 username
 
        $this->mail->Password   = "xxxxxxxxx";       // 163 password
 
       /// $this->mail->AddReplyTo('@163.com', 'YOUR_NAME');   //回复地址(可填可不填)
 
        //$this->mail->SetFrom('YOUR_GAMIL@163.com', 'YOUR_NAME');
 
    }
 
 
 
    public function sendmail($to, $to_name, $subject, $body){
 
        try{
 
            $this->mail->From = 'xxxx@163.com';
 
            $this->mail->FromName = 'xxxxxx';
 
            $this->mail->AddAddress($to, $to_name);
 
             
 
            $mail->WordWrap = 50;                                 // Set word wrap to 50 characters
 
            $this->mail->IsHTML(true);                                  // 使用html格式
 
 
 
            $this->mail->Subject = $subject;
 
            $this->mail->Body    = $body;
 
 
 
 
 
            $this->mail->Send();
 
                echo "Message Sent OK</p>\n";
 
 
 
        } catch (phpmailerException $e) {
 
            echo $e->errorMessage(); //Pretty error messages from PHPMailer
 
        } catch (Exception $e) {
 
            echo $e->getMessage(); //Boring error messages from anything else!
 
        }
 
    }
 
}
 
 
 
/* End of file mailer.php */
复制代码
发表于 2013-7-31 11:54:26 | 显示全部楼层
谢谢,分享。我这遇见个问题,发送完邮件后,返回去网站所有的js都失效了,但是js路径没什么问题,在浏览器谦容模式下出现的问题。怎么回事呢?

点评

兼容模式下出的问题? 那就是你的JS写得有问题哟。  发表于 2013-8-4 20:17
发表于 2013-8-9 09:59:26 | 显示全部楼层
蜗牛999 发表于 2013-7-31 11:54
谢谢,分享。我这遇见个问题,发送完邮件后,返回去网站所有的js都失效了,但是js路径没什么问题,在浏览器 ...

是的。谢谢你。   return  调用函数出问题了。

发表于 2013-10-10 14:29:30 | 显示全部楼层
先下载下来看看
发表于 2013-12-9 13:58:32 | 显示全部楼层
今天使用了一下phpmailer,发现QQ和163邮箱死活不能发邮件。
情况如下:
1、如果使用ssl,就提示ssl有问题,请配置PHP;
2、如果使用默认的tsl,就是提示smtp无法连接;

网上搜索了一下,发现有人说是scoket没开,虽有些莫名,但开启配置后发现还是没用;然后关了socket再开ssl,就成功了~~

根据之前网友和其它论坛网友的解释,我觉得原因如下:
1、为了防止垃圾邮件乱发,如果不使用ssl,则禁止其它服务器发送邮件(客户端可以);
2、如果使用ssl方式发邮件,则所在服务器必须启用ssl的dll,名称为:php_openssl.dll

本版积分规则