How to Send Gmail using CodeIgniter Email Library

In this post I would like to show you configuring Codeigniter email library to send emails using GMail SMTP server. Configuring and sending emails in Codeigniter application is not a tedious task, it is very simple and easy with few lines of code and config values you can send emails. You can set configuration options on fly or you can set config options of email library globally at applications/config/email.php.

Now I will explain how to send email using PHP and CodeIgniter Framework,you must load email library in order to send emails.

Message: mail() [function.mail]: Failed to connect to mailserver at “ssl://smtp.googlemail.com” port 465,
verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set()

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465
(Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?)

If those error occurred, make sure extension=php_smtp.dll and extension=php_openssl.dll uncommented in php.ini .If you are using xampp make sure you change php.ini in xampp/apache/bin/php.ini. If php.ini doesn’t exists to that directory, copy php.ini from xampp/php/php.ini to xampp/apache/bin/.

$this->email->set_newline enclose with double quotes. This is very important or else it does not work.Because PHP interpreter will consider \n as new line only when it is in enclosed with double quotes and if it in single quotes interpreter consider it as the literal character. So have a eye on it.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Subscribe
Notify of
guest
20 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Gábor Németh
Gábor Németh
4 years ago

$this->email->initialize($config);
this missing

arjun
4 years ago
Reply to  Gábor Németh

Hi Gabor, as we are loading email library with $config values ($this->load->library(’email’, $emailConfig);) we dont have to call initialize method.

Barbela Lee
Barbela Lee
4 years ago

Hello Arjun, thanks for your very good explanations and codes. I used your code but i still meet the error although i have copied the php.ini file into xampp/apache/bin. The error message is still the same.
“Message: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed”, “Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Unknown error)”, and “Message: fsockopen(): Failed to enable crypto”.. Below those error messages, i found this (shown in picture below).. Could you please help me to solve this? I don’t know why this happen, i could sending mail before but suddenly it couldn’t..

Muhamad Abdi Mulia
Muhamad Abdi Mulia
4 years ago
Reply to  Barbela Lee

dont froget to unable following two security settings in google.
http://stackoverflow.com/posts/32017154/revisions

Barbela Lee
Barbela Lee
4 years ago

thanks abdi for your help, but unfortunately still.. it still doesn’t send any emails as verification although i already set the security settings..

Muhamad Abdi Mulia
Muhamad Abdi Mulia
4 years ago
Reply to  Barbela Lee

still get the same error?

Barbela Lee
Barbela Lee
4 years ago

ya, the same.. There are 3 errors appear :
1. Message: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
2. Message: fsockopen(): Failed to enable crypto
3. Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Unknown error)

arjun
4 years ago
Reply to  Barbela Lee

Change $this->email->set_newline(“rn”); to $this->email->set_newline(“rn”);

Barbela Lee
Barbela Lee
4 years ago
Reply to  arjun

why i still get the same error although i changed the new line into $this->email->set_newline(“rn”); ?

arjun
4 years ago
Reply to  Barbela Lee

Hey Here is the working demo files – https://github.com/iarjunphp/Send-Gmail-using-CodeIgniter-Email-Library . check with this. If you still need any info let me know

gilang aprila
gilang aprila
3 years ago
Reply to  arjun

I found the same error, when I have followed the flow,
please help me ??

arjun
3 years ago
Reply to  gilang aprila

Can you share error message?

RA
RA
4 years ago

How to Use MIME for html use in smtp ..i am not able to send proper html format

arjun
4 years ago
Reply to  RA

You do not have to set MIME types, just use – mailtype config property to set mail type (html or text

arjun
4 years ago
Reply to  RA

If you want to pass view to email write something like this – $message = $this->load->view(‘welcome_message’,[],true);

Pankaj Sarkar
Pankaj Sarkar
4 years ago

I’m using your code from github but still this error is coming.
Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (No connection could be made because the target machine actively refused it. )

Abdurrahman Ukasyah
Abdurrahman Ukasyah
3 years ago

Thanks man. After spend couple hours, found this site. Works like a charm!

foram dungrani
foram dungrani
3 years ago

Message: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

Message: fsockopen(): Failed to enable crypto

Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Unknown error)

i m getting this 3 error
can you help me out of this

aysha
aysha
1 month ago

my php mailer is not sending any mails

DMCA.com Protection Status
20
0
Would love your thoughts, please comment.x
()
x