Home > Codeigniter, Computing > Gmail smtp in codeigniter on WAMP

Gmail smtp in codeigniter on WAMP

March 22nd, 2011

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:

  1. 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.
  2. 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.
  3. 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('example@example.co.uk', 'My Name');
    $this->email->subject('Email Test');
    $this->email->message('Your order: '.$order_id . ' was submitted successfully');
  4. 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).

Codeigniter, Computing

  1. Adil
    | #1

    Big Thanks !

  2. Mark
    | #2

    Thanks man, I spent few hours with fake send mail and other crap, but this is clean and easy solution. Big like.

  1. No trackbacks yet.