其实手册上已经讲得比较好了。但是有些不太对味,排版不太符合国人的习惯。闲话不说了,淡水喜欢直奔主题。 以Gmail为例,其他的更加简单(smtp_host和port改一下就行了,而且一般的smtp都无需ssl的)。要发信,先要配置。 配置有两种方式,方式一直接写在发送mail代码的前面,如下: $config[‘protocol’] = ‘smtp’; $config[‘smtp_host’] = ‘ssl://smtp.gmail.com’; $config[‘smtp_user’] = ‘username@gmail.com’; $config[‘smtp_pass’] = ‘password’; $config[‘smtp_port’] = ‘465’; $config[‘smtp_timeout’] = ‘5’; $config[‘newline’] = “rn”; $config[‘crlf’] = “rn”;
$this->email->initialize($config); 方式二,创建一个配置文件config/email.php,内容如下: $config[‘protocol’] = ‘smtp’; $config[‘smtp_host’] = ‘ssl://smtp.gmail.com’; $config[‘smtp_user’] = ‘username@gmail.com’; $config[‘smtp_pass’] = ‘password’; $config[‘smtp_port’] = ‘465’; $config[‘smtp_timeout’] = ‘5’; $config[‘newline’] = “rn”; $config[‘crlf’] = “rn”; ok,现在可以发信了。 $this->load->library(‘email’); $this->email->from(‘username@gmail.com’, ‘your_name’); $this->email->to(‘your_friend@xxx.com’); $this->email->subject(‘subject’); $this->email->message(‘this is the mail content’); $this->email->send(); 啰嗦一下,用Gmail发信,不太容易被当作垃圾邮件,但是主机要支持ssl才可以,否则是发不出的。其他免费的stmp也有不错的,而且不用ssl支持。比如tom和qq了。
最后修改于 2008-10-08