CodeIgniter and Gmail SMTP option using SSL scoket

I use Gmail SMTP to send email from a web application that I wrote using CodeIgniter with PHP 5.3 without problems until recently. This is a piece of code:

  $config['protocol']   = 'smtp';
  $config['smtp_host']  = $this->smtp_host;
  $config['smtp_port']  = $this->smtp_port;
  $config['smtp_user']  = $this->smtp_username;
  $config['smtp_pass']  = $this->smtp_password;
  $config['mailtype']   = $this->email_type;
  $config['newline'] = "\r\n";
  $this->load->library('email', $config);

  $this->email->from($email_sender, $email_sender_name);
  $this->email->to($email_to);
  $this->email->subject($message_subject);
  $this->email->message($message_content);
  $result = $this->email->send();

When I use "ssl://smtp.gmail.com"as a host and 465as a port, I got this error in the log:

DEBUG - 2010-08-06 17:19:24 --> Email Class Initialized
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out) /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1652
DEBUG - 2010-08-06 17:19:45 --> Language file loaded: language/english/email_lang.php
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:19:45 --> Severity: Warning  --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818

I don't know if this is related, but before I updated my PHP to PHP 5.3, the same code worked fine. If these are problems with a firewall or Internet connection, I can still send an email using gmail smtp to Thunderbird.

After I look at different forums, I have tips for this test:

$ openssl s_client -starttls smtp -crlf -connect smtp.gmail.com:587
CONNECTED(00000003)
depth=1 /C=US/O=Google Inc/CN=Google Internet Authority
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com
   i:/C=US/O=Google Inc/CN=Google Internet Authority
 1 s:/C=US/O=Google Inc/CN=Google Internet Authority
   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
...cut...
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com
issuer=/C=US/O=Google Inc/CN=Google Internet Authority
---
No client certificate CA names sent
---
SSL handshake has read 1901 bytes and written 335 bytes
---
New, TLSv1/SSLv3, Cipher is RC4-MD5
Server public key is 1024 bit
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : RC4-MD5
    Session-ID: 2CA08CABBE21653238292DEDF30D119428970FAA284263C92480DA5283AFE013
    Session-ID-ctx: 
    Master-Key: B3F6D4423DC14E24E894D7AD7107B4A640839F2BF90233714EC5BF0D139611E65655902B50AEA3BD67373A21338526B0
    Key-Arg   : None
    Start Time: 1281086948
    Timeout   : 300 (sec)
    Verify return code: 20 (unable to get local issuer certificate)
---
250 ENHANCEDSTATUSCODES

when using the same tool to test the connection sslgive me a timeout:

$ openssl s_client -ssl2 -crlf -connect smtp.gmail.com:465
connect: Connection timed out
connect:errno=110

"tls://smtp.gmail.com" 587 , :

DEBUG - 2010-08-06 17:26:10 --> Email Class Initialized
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1652
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fsockopen(): Failed to enable crypto /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1652
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fsockopen(): unable to connect to tls://smtp.googlemail.com:587 (Unknown error) /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1652
DEBUG - 2010-08-06 17:26:10 --> Language file loaded: language/english/email_lang.php
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fwrite() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1795
ERROR - 2010-08-06 17:26:10 --> Severity: Warning  --> fgets() expects parameter 1 to be resource, boolean given /data/donny/Projects/workspace/codeigniter/libraries/Email.php 1818
  • , , ssl://smtp.gmail.com:465
  • -, tls PHP 5.3? , , CodeIgniter .

.

+3
2

Google.com, Secure SMTP, CI.

http://codeigniter.com/forums/viewthread/158882/

SMTP- ( Exchange) SSL- SMTP TLS (STARTTLS, RFC 3207). , . 1.7.2. , .

: SMTP- (tcp://_, 25 587). config ($ config ['starttls] = TRUE;)

TLS (.. " " phpinfo()).

+1

Source: https://habr.com/ru/post/1758362/


All Articles