用户
 找回密码
 入住 CI 中国社区
搜索
查看: 4307|回复: 2
收起左侧

[讨论/交流] 简单详细的示例:使用email类来发送邮件

[复制链接]
发表于 2012-2-26 14:16:17 | 显示全部楼层 |阅读模式
今天使用了CI的email类来发送邮件。我的SMTP服务器地址是使用163邮箱的。
在config文件夹下有一个配置文件email.php,代码如下:
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
      $config['protocol'] = 'smtp';
      $config['smtp_host'] = 'smtp.163.com';
      $config['smtp_user'] = 'abcd@163.com';//这里写上你的163邮箱账户
      $config['smtp_pass'] = 'abcd';//这里写上你的163邮箱密码
      $config['mailtype'] = 'html';
       $config['validate'] = true;
     $config['priority'] = 1;
     $config['crlf']  = "\r\n";
     $config['smtp_port'] = 25;
     $config['charset'] = 'utf-8';
    $config['wordwrap'] = TRUE;
?>
控制器email.php代码如下:
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class Email extends Controller{
    function __construct(){
      parent::__construct();
    }
    function index(){
        $this->load->library('email');
        $this->email->from('abcd@163.com', '你的名字');//发件人
        $this->email->to('123456@163.com'); //收件人的qq邮箱 (注意:('123456@qq.com'),QQ邮箱也能成功接收)
        $this->email->subject('测试email类');
        $this->email->message('这次能发送了吗?');
        $this->email->send();
        echo $this->email->print_debugger();
    }
}
?>
注意:这里当把SMTP的服务器地址设置成'smtp.163.com'的时候,可以向163邮箱发送,也可以向qq邮箱发送,但是当把SMTP的服务器地址设置成'smtp.163.qq'的时候,在像其它的邮箱来发送邮件的时候,就发送不成功,也就是说你使用QQ邮箱给他人发送邮件的时候发送不出去,不知道,有没有高手遇到过这种情况?求解!!!
 楼主| 发表于 2012-2-26 14:20:44 | 显示全部楼层
我再补充一下:当我使用qq邮箱发送的时候,smtp服务器的地址改成了相应的qq的:
$config['smtp_host'] = 'smtp.qq.com';
邮箱和密码什么的都对,但是就是发送不成功啊???
发表于 2012-2-26 15:59:49 | 显示全部楼层
人家各个邮箱有不同的权限管理方案。发外网,谷歌的企业邮箱我感觉是最好的了,支持php。

本版积分规则