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

[程序 App] 用CI实现Email功能

[复制链接]
发表于 2013-8-12 15:47:24 | 显示全部楼层 |阅读模式
修改配置文件:D:\wamp\www\tuts\application\config下的config.php文件如下:$config['base_url']        = "http://localhost/tuts/index.php/";
$config['server_root'] = $_SERVER['DOCUMENT_ROOT'];

在网站根目录下建立如下目录:D:\wamp\www\tuts\attachments存放附件
浏览器中输入:localhost/tuts/index.php/email/
控制器中的代码如下:
class Email extends Controller
{
        function __construct()
        {
                parent::Controller();
        }
       
        function index()
        {       
                $config=Array(
                        'protocol' => 'smtp',
                    'smtp_host'=>  "smtp.qq.com",                // SMTP Server.  Example: mail.earthlink.net
                'smtp_user'=>  "*******@qq.com",                // SMTP Username
                'smtp_pass'=>  "*******",        // SMTP Password
                'smtp_port'=>  "25"                // SMTP Port,default
               
                );
                $this->load->library('email', $config);
                $this->email->set_newline("\r\n");
               
                $this->email->from('*****@qq.com', 'yangli');
                $this->email->to('******@163.com');               
                $this->email->subject('This is an email test2222!');               
                $this->email->message('It is working. Great!ok!');
               
                $path = $this->config->item('server_root');
                $file = $path . '/tuts/attachments/yourInfo.txt';
               
                $this->email->attach($file);
               
                if($this->email->send())
                {
                        echo 'Your email was sent, fool.';
                }
               
                else
                {
                        show_error($this->email->print_debugger());
                }
        }
}



本版积分规则