Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email with gmail smtp with codeigniter email library

<?php class Email extends Controller {      function Email()     {         parent::Controller();            $this->load->library('email');     }      function index()     {         $config['protocol']    = 'smtp';         $config['smtp_host']    = 'ssl://smtp.gmail.com';         $config['smtp_port']    = '465';         $config['smtp_timeout'] = '7';         $config['smtp_user']    = '[email protected]';         $config['smtp_pass']    = '*******';         $config['charset']    = 'utf-8';         $config['newline']    = "\r\n";         $config['mailtype'] = 'text'; // or html         $config['validation'] = TRUE; // bool whether to validate email or not                $this->email->initialize($config);          $this->email->from('[email protected]', 'myname');         $this->email->to('[email protected]');           $this->email->subject('Email Test');         $this->email->message('Testing the email class.');            $this->email->send();          echo $this->email->print_debugger();          $this->load->view('email_view');     } } 

I am getting this error:

A PHP Error was encountered Severity: Warning Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out) Filename: libraries/Email.php Line Number: 1641 

Using PORT 25/587

I got this error:

A PHP Error was encountered Severity: Warning Message: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:func(119):reason(252) Filename: libraries/Email.php Line Number: 1641 

I don't want to use phpmailer now. (Actually I have tried to use phpmailer, but I failed).

How do I solve this problem guys?

like image 826
Shiv Avatar asked Oct 12 '09 15:10

Shiv


2 Answers

$config = Array(     'protocol' => 'smtp',     'smtp_host' => 'ssl://smtp.googlemail.com',     'smtp_port' => 465,     'smtp_user' => 'xxx',     'smtp_pass' => 'xxx',     'mailtype'  => 'html',      'charset'   => 'iso-8859-1' ); $this->load->library('email', $config); $this->email->set_newline("\r\n");  // Set to, from, message, etc.  $result = $this->email->send(); 

From the CodeIgniter Forums

like image 132
Teej Avatar answered Sep 19 '22 17:09

Teej


You need to enable SSL in your PHP config. Load up php.ini and find a line with the following:

;extension=php_openssl.dll

Uncomment it. :D

(by removing the semicolon from the statement)

extension=php_openssl.dll

like image 39
Cerebro Avatar answered Sep 18 '22 17:09

Cerebro