配置有两种方式,方式一直接写在发送mail代码的前面,如下:
方式二,创建一个配置文件config/email.php,内容如下:
ok,现在可以发信了。
- $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/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('your_friend@xxx.com');
- $this->email->subject('subject');
- $this->email->message('this is the mail content');
- $this->email->send();