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:
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'ssl://smtp.gmail.com';
    $config['smtp_port'] = '465';
    $config['smtp_timeout']="30";
    $config['smtp_user'] = 'example@gmail.com'; //or example@gmailappsdomain.com
    $config['smtp_pass'] = 'password';
    $config['charset'] = 'utf-8';
    $config['newline'] = "\r\n";
    $config['crlf'] = "\r\n";
    $config['mailtype'] = "html";
    ?>

    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->load->library('email');
    $this->email->from('example@example.co.uk', 'My Name');
    $this->email->to('dan@example-address.com');
    $this->email->subject('Email Test');
    $this->email->message('Your order: '.$order_id . ' was submitted successfully');
    $this->email->send();
    }
  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).

Dan Spencer Codeigniter, Computing

  1. Adil
    July 20th, 2011 at 21:19 | #1

    Big Thanks !

  1. No trackbacks yet.