注册Gmail地址:www.gmail.com/?M=A
用Gmail发信,不太容易被当作垃圾邮件,但是主机要支持ssl才可以,否则是发不出的。
其他的更加简单(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'] = "/r/n";
$config['crlf'] = "/r/n";
$this->email->initialize($config);
$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'] = "/r/n";
$config['crlf'] = "/r/n";
$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'] = "/r/n";
$config['crlf'] = "/r/n";
ok,现在可以发信了。
$
this
->
load
->
library(
'
email
'
);
$ this -> email -> from( ' username@gmail.com ' , ' your_name ' );
$ this -> email -> to( ' CTOChina.Net@xxx.com ' );
$ this -> email -> subject( ' subject ' );
$ this -> email -> message( ' this is the mail content ' );
$ this -> email -> send();
$ this -> email -> from( ' username@gmail.com ' , ' your_name ' );
$ this -> email -> to( ' CTOChina.Net@xxx.com ' );
$ this -> email -> subject( ' subject ' );
$ this -> email -> message( ' this is the mail content ' );
$ this -> email -> send();
PS:Codeigniter讨论:http://www.ctochina.net/topic/showtopic/4.html