php使用CI发送qq和163邮件

时间:2021-12-17 13:06:36

1.需求

发送邮件

2.介绍

使用CI框架的email类库发送邮件,这里演示QQ和163

3.163使用教程

a.先去163邮件开启smtp邮件。

b.在CI的控制器里写下面的代码

$this->load->library('email');            //加载CI的email类

        $config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.163.com';
$config['smtp_user'] = '18367724000@163.com';//这里写上你的163邮箱账户
$config['smtp_pass'] = 'storecode8881111';//这里写上你的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;
$this->email->initialize($config); //以下设置Email内容
$this->email->from('18367724000@163.com', 'mike');
$this->email->to('3090333013@qq.com');
$this->email->subject('Email Test');
$this->email->message('<font color=red>Testing the email class.</font>');
$this->email->attach('application\controllers\1.jpeg'); //相对于index.php的路径 $this->email->send();

4.QQ使用教程

a.先去qq邮件开启smtp邮件。

b.在CI的控制器里写下面的代码

$this->load->library('email');            //加载CI的email类

        //以下设置Email参数
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.qq.com';
$config['smtp_user'] = '100000356@qq.com';
$config['smtp_pass'] = 'dxwgjbziifqhbggj';
$config['smtp_port'] = '465';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['newline'] = PHP_EOL;
$config['crlf'] = PHP_EOL;
$this->email->initialize($config); //以下设置Email内容
$this->email->from('18367724000@163.com', 'mike');
$this->email->to('3090333013@qq.com');
$this->email->subject('Email Test');
$this->email->message('<font color=red>Testing the email class.</font>');
$this->email->attach('application\controllers\1.jpeg'); //相对于index.php的路径 $this->email->send();

阿里云ecs关闭25端口的,要用163的465端口来发送

  $this->load->library('email');            //加载CI的email类
$smtp= $this->config->item("smtp");
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.163.com';
$config['smtp_user'] = $smtp['user'];//这里写上你的163邮箱账户
$config['smtp_pass'] = $smtp['password'];//这里写上你的163邮箱密码
$config['mailtype'] = 'html';
$config['validate'] = true;
$config['priority'] = 1;
$config['crlf'] = "\r\n";
$config['smtp_port'] = 465;
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$this->email->initialize($config); //以下设置Email内容
$this->email->from('18360@163.com', 'mike');
$this->email->to($smtp['receiver']);
$this->email->subject($subject);
$this->email->message($message); $result = $this->email->send();

  

单独可以使用的!!!!!

http://blog.csdn.net/qq_16542775/article/details/47817679

5.总结

要注意先开启smtp功能才能发短信,密码是开启之后提供的,而不是邮件的登录密码。

参考资料:http://www.phpddt.com/mvc/79.html

https://www.ipbbs.net/viewtopic.php?pid=119