Welcome Guest, Not a member yet? Register   Sign In
Gmail SMTP using SSL/TLS
#1

[eluser]wrs[/eluser]
This post is no longer accurate for use with CodeIgniter2, thankfully biojazard has revised the code in his post later in this thread. I'd link you to it, but im apparently being punished for not being 'active'.

To help lift any bad feelings towards my absence Id like to use several smileys to seperate this edit with the original post.

:wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow: :wow:

I only heard about codeigniter a couple days ago so forgive me if im repeating something found either on the forums or bugtracker etc.

I've been trying to use the included Email library in conjunction with my favourite Google Mail service and, like many others, i've been having many problems.

Google Mail requires encryption ( SSL/TLS ) for its SMTP access and it has been noted that this is not something that CodeIgniter currently supports. Understanding this I decided to go about either modifying or rewriting the CI_Email class to include these features.

After some reading it seems that SSL and TLS are in fact the same thing ( the protocol was renamed? ). I think its fair to say the most common misunderstanding of these two protocols are that SSL is encryption enabled during connection and that TLS is encryption enabled on the fly after a connection has been made ( hence the STARTTLS ESMTP command ).

In any case, after several hours of farting about, i've realised that CodeIgnighter will indeed work with the Gmail service without any modification of the core classes.

Firstly, your PHP installation must include support for openssl ( either compiled in, or with the php_openssl.dll extension loaded ). You will want to read the pages surrounding OpenSSL Installation within the PHP Manual.

With that done, you just need your standard use of the email library with a few noticable changes from the norm:

Code:
$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => '[email protected]',
    'smtp_pass' => 'your_password',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

$this->email->from('[email protected]', 'Your Name');
$this->email->to('[email protected]');

$this->email->subject(' CodeIgniter Rocks Socks ');
$this->email->message('Hello World');


if (!$this->email->send())
    show_error($this->email->print_debugger());
else
    echo 'Your e-mail has been sent!';

The important parts of the above code are the inclusion of the ssl:// protocol before the smtp hostname, and setting the newline variable to CRLF. The port value of 465 may also be important ( 25 doesnt work at least).

Everything is now working as expected here, hope this helps someone.

Also, I noticed that the documentation recommends using $this->email->initialize($config_array) for setting your mailing preferences however it does not take the nesecarry steps to enable authentication should smtp_user & smtp_pass be defined. The good news is that you can pass the exact same $config_array to your $this->load->library(); call like so:
Code:
$this->load->library('email', $config_array);

This will do exactly the same as initialize($config_array) but will properly configure for authentication should be it required. Perhaps there is a reason for initalize()'s behaviour but the documentation is misleading and doesnt mention $this->load->library('email', $config_array); at all.


I havnt decided if I will use CodeIgnigter as part of my usual dev toolset, its certainly an interesting framework, but i've been impressed with both it and its community so far. So keep up the good work ;D


Messages In This Thread
Gmail SMTP using SSL/TLS - by El Forum - 07-09-2008, 08:16 PM
Gmail SMTP using SSL/TLS - by El Forum - 07-10-2008, 09:08 AM
Gmail SMTP using SSL/TLS - by El Forum - 07-19-2008, 12:01 AM
Gmail SMTP using SSL/TLS - by El Forum - 07-21-2008, 10:12 PM
Gmail SMTP using SSL/TLS - by El Forum - 08-01-2008, 04:13 PM
Gmail SMTP using SSL/TLS - by El Forum - 09-01-2008, 11:50 PM
Gmail SMTP using SSL/TLS - by El Forum - 09-02-2008, 11:32 AM
Gmail SMTP using SSL/TLS - by El Forum - 01-15-2009, 05:25 AM
Gmail SMTP using SSL/TLS - by El Forum - 01-15-2009, 08:07 AM
Gmail SMTP using SSL/TLS - by El Forum - 02-24-2009, 08:06 PM
Gmail SMTP using SSL/TLS - by El Forum - 04-07-2009, 12:46 PM
Gmail SMTP using SSL/TLS - by El Forum - 05-23-2009, 07:44 AM
Gmail SMTP using SSL/TLS - by El Forum - 07-06-2009, 03:56 PM
Gmail SMTP using SSL/TLS - by El Forum - 07-06-2009, 06:35 PM
Gmail SMTP using SSL/TLS - by El Forum - 07-06-2009, 11:03 PM
Gmail SMTP using SSL/TLS - by El Forum - 07-07-2009, 08:06 AM
Gmail SMTP using SSL/TLS - by El Forum - 07-15-2009, 03:39 PM
Gmail SMTP using SSL/TLS - by El Forum - 07-29-2009, 03:26 AM
Gmail SMTP using SSL/TLS - by El Forum - 08-01-2009, 09:09 PM
Gmail SMTP using SSL/TLS - by El Forum - 08-02-2009, 10:11 PM
Gmail SMTP using SSL/TLS - by El Forum - 08-23-2009, 09:02 PM
Gmail SMTP using SSL/TLS - by El Forum - 09-22-2009, 10:38 AM
Gmail SMTP using SSL/TLS - by El Forum - 09-22-2009, 10:43 AM
Gmail SMTP using SSL/TLS - by El Forum - 01-27-2010, 12:41 AM
Gmail SMTP using SSL/TLS - by El Forum - 04-26-2010, 02:47 AM
Gmail SMTP using SSL/TLS - by El Forum - 04-26-2010, 02:54 AM
Gmail SMTP using SSL/TLS - by El Forum - 06-14-2010, 07:35 AM
Gmail SMTP using SSL/TLS - by El Forum - 09-15-2010, 02:48 PM
Gmail SMTP using SSL/TLS - by El Forum - 10-22-2010, 09:29 PM
Gmail SMTP using SSL/TLS - by El Forum - 03-19-2011, 05:03 AM
Gmail SMTP using SSL/TLS - by El Forum - 04-05-2011, 11:42 AM
Gmail SMTP using SSL/TLS - by El Forum - 05-02-2011, 10:43 PM
Gmail SMTP using SSL/TLS - by El Forum - 05-03-2011, 06:19 AM
Gmail SMTP using SSL/TLS - by El Forum - 09-15-2013, 05:06 AM
Gmail SMTP using SSL/TLS - by El Forum - 04-06-2014, 01:39 PM
Gmail SMTP using SSL/TLS - by El Forum - 05-05-2014, 03:59 AM
Gmail SMTP using SSL/TLS - by El Forum - 08-13-2014, 08:11 AM
Gmail SMTP using SSL/TLS - by El Forum - 08-13-2014, 08:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB