<?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'] = 'mygmail@gmail.com';
$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('mygmail@gmail.com', 'myname');
$this->email->to('target@gmail.com');
$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?
send html email via codeiginater
It can be this:
Error while sending an email with CodeIgniter
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
From the CodeIgniter Forums
Perhaps your hosting server and email server are located at same place and you don't need to go for smtp authentication. Just keep every thing default like:
or
it works for me.
Another option I have working, in a linux server with Postfix:
First, configure CI email to use your server's email system: eg, in
email.php
, for exampleThen configure your postfix to relay the mail to google (perhaps depending on the sender address). You'll probably need to put you user-password settings in
/etc/postfix/sasl_passwd
(docs)This is much simpler (and less fragmente) if you have a linux box, already configured to send some/all of its outgoing emails to Google.