由於自己租的 slicehost 只有 256MB 的記憶體, 架 mail server 又很麻煩 (因為我也不懂 XD), 又似乎 mail 有啥反解的問題, 而直接透過 sendmail 這樣寄信會被當成垃圾信, 所以就申請了 Google app, 然後用申請到的帳號透過 SMTP 來發送信件。 由於 Gmail 的 SMTP 又跟一般的設定稍微不一樣(有 SSL), 所以記錄一下。
在 CodeIgniter 上面其實就只是設定個 config 檔就可以了, 設定檔如下:
application/config/email.php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_user'] = 'your_email';
$config['smtp_pass'] = 'your_password';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '5';
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
這個設定檔寫好之後, 就依照 user_guide 寫的方式使用 email library 即可。
$this->load->library('email');
$this->email->from('foo@bar.com', 'foo');
$this->email->to('bar@foo.com');
$this->email->subject('email subject');
$this->email->message('this is the mail content');
$this->email->send();





[...] 有了之前設定 CodeIgniter 透過 Gmail 發信的經驗, 這次設定 Kohana 就快很多了 :p [...]
沒辦法用你的辦法耶
試過好多次
總是會出現
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?)
Filename: libraries/Email.php
Line Number: 1564
我的環境是xampplite+codeigniter
PHP 給你的錯誤訊息就有提到
Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?
就是說, 你的 PHP 並沒有開啟或編譯進 ssl 這個 protocol
不过 唯一的缺憾就是通过google发送邮件的速度稍稍有点慢
[...] 有了之前設定 CodeIgniter 透過 Gmail 發信的經驗, 這次設定 Kohana 就快很多了 :p [...]