Gmail smtp in codeigniter on WAMP
I was having real issues getting gmail smtp working on WAMP, using the great php framework Codeigniter. I followed many guides, but kept getting erred when calling the email->send() method. Eventually I worked it out! So here are my steps:
- Enable php_openssl in WAMP. This is done by clicking the WAMP tray icon -> PHP -> PHP Extensions -> php_openssl (make sure it has a tick beside it). WAMP will automatically insert the line in the php.ini file to include this extension, so there is no need to uncomment it in php.ini. In fact if you do, you will get a warning message in the apache error_log.
- make sure your email settings (application/config/email.php) in codeigniter look like this:
NOTICE the double quotes in the newline and crlf array variables! This is what was breaking my script and took over 3 hours to figure out! single quotation marks will not work! smtp_timeout is not really necessary and defaults to 5 (secs) but I have it up high here because i’m in development environment.
- Everything should be working now… Just write a script to test it out. I put this method in the welcome controller
public function order_notification($order_id)
$this->email->from('email@example.com', 'My Name');
$this->email->message('Your order: '.$order_id . ' was submitted successfully');
- Now call this method in the browser by visiting: http://localhost/welcome/order_notification/1234 (notice I have mod_rewrite so no index.php call in address bar (Apache does that for me).