Codeigniter Send email not Working SMTP in hostinger [duplicate] - php

<?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?

$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

According to the CI docs (CodeIgniter Email Library)...
If you prefer not to set preferences using the above method, you can
instead put them into a config file. Simply create a new file called
the email.php, add the $config array in that file. Then save the file
at config/email.php and it will be used automatically. You will NOT
need to use the $this->email->initialize() function if you save your
preferences in a config file.
I was able to get this to work by putting all the settings into application/config/email.php.
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'YOUREMAILHERE#gmail.com';
$config['smtp_pass'] = 'YOURPASSWORDHERE';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;
Then, in one of the controller methods I have something like:
$this->load->library('email'); // Note: no $config param needed
$this->email->from('YOUREMAILHERE#gmail.com', 'YOUREMAILHERE#gmail.com');
$this->email->to('SOMEEMAILHERE#gmail.com');
$this->email->subject('Test email from CI and Gmail');
$this->email->message('This is a test.');
$this->email->send();
Also, as Cerebro wrote, I had to uncomment out this line in my php.ini file and restart PHP:
extension=php_openssl.dll

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

Change it to the following:
$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "blablabla#gmail.com";
$config['smtp_pass'] = "yourpassword";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('blablabla#gmail.com', 'Blabla');
$list = array('xxx#gmail.com');
$ci->email->to($list);
$this->email->reply_to('my-email#gmail.com', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->send();

send html email via codeiginater
$this->load->library('email');
$this->load->library('parser');
$this->email->clear();
$config['mailtype'] = "html";
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('email#example.com', 'Website');
$list = array('xxxxxxxx#archmage.lk', 'xxxxx#gmail.com');
$this->email->to($list);
$data = array();
$htmlMessage = $this->parser->parse('messages/email', $data, true);
$this->email->subject('This is an email test');
$this->email->message($htmlMessage);
if ($this->email->send()) {
echo 'Your email was sent, thanks chamil.';
} else {
show_error($this->email->print_debugger());
}

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 example
# alias to postfix in a typical Postfix server
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
Then 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.

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:
$config = array(
'protocol' => '',
'smtp_host' => '',
'smtp_port' => '',
'smtp_user' => 'yourname#gmail.com',
'smtp_pass' => '**********'
);
or
$config['protocol'] = '';
$config['smtp_host'] = '';
$config['smtp_port'] = ;
$config['smtp_user'] = 'yourname#gmail.com';
$config['smtp_pass'] = 'password';
it works for me.

It can be this:
If you are using cpanel for your website smtp restrictions are problem
and cause this error. SMTP Restrictions
Error while sending an email with CodeIgniter

There is very simple answer to this . and the only solution that worked at the en was this configuration ..i only had to chnage the port to 587 and overwrite the codeignitor default "Email.php"
$config = array( 'protocol' => 'smtp', 'smtp_host' => 'smtp.gmail.com', 'smtp_port' => 587, 'smtp_user' => 'admin#cafeadmin.com.au', 'smtp_pass' => '1800#Footscray123!' );$this->load->library('email', $config);$this->email->initialize($config);

Related

CodeIgniter sending Email using Gmail SMTP [duplicate]

<?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?
$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
According to the CI docs (CodeIgniter Email Library)...
If you prefer not to set preferences using the above method, you can
instead put them into a config file. Simply create a new file called
the email.php, add the $config array in that file. Then save the file
at config/email.php and it will be used automatically. You will NOT
need to use the $this->email->initialize() function if you save your
preferences in a config file.
I was able to get this to work by putting all the settings into application/config/email.php.
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'YOUREMAILHERE#gmail.com';
$config['smtp_pass'] = 'YOURPASSWORDHERE';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;
Then, in one of the controller methods I have something like:
$this->load->library('email'); // Note: no $config param needed
$this->email->from('YOUREMAILHERE#gmail.com', 'YOUREMAILHERE#gmail.com');
$this->email->to('SOMEEMAILHERE#gmail.com');
$this->email->subject('Test email from CI and Gmail');
$this->email->message('This is a test.');
$this->email->send();
Also, as Cerebro wrote, I had to uncomment out this line in my php.ini file and restart PHP:
extension=php_openssl.dll
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
Change it to the following:
$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "blablabla#gmail.com";
$config['smtp_pass'] = "yourpassword";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('blablabla#gmail.com', 'Blabla');
$list = array('xxx#gmail.com');
$ci->email->to($list);
$this->email->reply_to('my-email#gmail.com', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->send();
send html email via codeiginater
$this->load->library('email');
$this->load->library('parser');
$this->email->clear();
$config['mailtype'] = "html";
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('email#example.com', 'Website');
$list = array('xxxxxxxx#archmage.lk', 'xxxxx#gmail.com');
$this->email->to($list);
$data = array();
$htmlMessage = $this->parser->parse('messages/email', $data, true);
$this->email->subject('This is an email test');
$this->email->message($htmlMessage);
if ($this->email->send()) {
echo 'Your email was sent, thanks chamil.';
} else {
show_error($this->email->print_debugger());
}
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 example
# alias to postfix in a typical Postfix server
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
Then 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.
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:
$config = array(
'protocol' => '',
'smtp_host' => '',
'smtp_port' => '',
'smtp_user' => 'yourname#gmail.com',
'smtp_pass' => '**********'
);
or
$config['protocol'] = '';
$config['smtp_host'] = '';
$config['smtp_port'] = ;
$config['smtp_user'] = 'yourname#gmail.com';
$config['smtp_pass'] = 'password';
it works for me.
It can be this:
If you are using cpanel for your website smtp restrictions are problem
and cause this error. SMTP Restrictions
Error while sending an email with CodeIgniter
There is very simple answer to this . and the only solution that worked at the en was this configuration ..i only had to chnage the port to 587 and overwrite the codeignitor default "Email.php"
$config = array( 'protocol' => 'smtp', 'smtp_host' => 'smtp.gmail.com', 'smtp_port' => 587, 'smtp_user' => 'admin#cafeadmin.com.au', 'smtp_pass' => '1800#Footscray123!' );$this->load->library('email', $config);$this->email->initialize($config);

Codeigniter Email PHP SMPT Error, cannot send mail through Gmail

I am currently trying to send an email or verification email after I've done signing up. The problem is I cannot send a verification through gmail because of this error:
The following SMTP error was encountered: Unable to send email using
PHP SMTP. Your server might not be configured to send mail using this
method.
I've already tried searching for solution here in stackoverflow, but I haven't found any solution that works for my problem.i have also done changing the smtp_port to 465 but still, it didn't solve my problem.
I am using Localhost and I configured the php.ini and sendmail.ini on xampp folder.
php.ini
[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = qwerty#gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Send mail
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=qwerty#gmail.com
auth_password=qwertyqwerty
force_sender=qwerty#gmail.com
my Code
//get user inputs
$email = $this->input->post('email');
$password = $this->input->post('password');
//generate simple random code
$set = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$code = substr(str_shuffle($set), 0, 12);
//insert user to users table and get id
$user['email'] = $email;
$user['password'] = $password;
$user['code'] = $code;
$user['active'] = false;
$id = $this->users_model->insert($user);
//set up email
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 587,
'smtp_user' => 'qwerty#gmail.com', // change it to yours
'smtp_pass' => 'qwertyqwerty', // change it to yours
'smtp_timeout' => "",
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE,
'validate' => FALSE
);
$message = "
<html>
<head>
<title>Verification Code</title>
</head>
<body>
<h2>Thank you for Registering.</h2>
<p>Your Account:</p>
<p>Email: ".$email."</p>
<p>Password: ".$password."</p>
<p>Please click the link below to activate your account.</p>
<h4><a href='".base_url()."user/activate/".$id."/".$code."'>Activate My Account</a></h4>
</body>
</html>
";
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($config['smtp_user']);
$this->email->to($email);
$this->email->subject('Signup Verification Email');
$this->email->message($message);
//sending email
if($this->email->send()){
$this->session->set_flashdata('message','Activation code sent to email');
}
else{
$this->session->set_flashdata('message', $this->email->print_debugger());
}
You don't need to change php.ini or sendmail.ini to send SMTP. Please make it default.
After I look at your SMTP configuration, You missed a little thing but seems important: crypto protocol.
You can set crypto protocol inside $config['smtp_host'] like so:
$config['smtp_host'] = 'ssl://smtp.googlemail.com'
Or you can also try this config:
$config['protocol'] = "smtp";
$config['smtp_host'] = "smtp.googlemail.com";
$config['smtp_port'] = "465"; // if you decided to use 465, then set smtp crypto to ssl, else for example 587, you need to set smtp crypto to tls.
$config['smtp_crypto'] = 'ssl'; // this is based on your smtp port -> ssl/tls
$config['smtp_timeout'] = "400";
$config['smtp_user'] = "youruser#gmail.com";
$config['smtp_pass'] = "yourpassword%&^$&$";
$config['validate'] = true;
$config['charset'] = 'utf-8';
$config['mailtype'] = "html";
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
Then assign $config to email library: $this->load->library('email', $config);
Please do check less security (in gmail setting) was: enabled.
Otherwise, you can create email.php as an email config library inside application/config/email.php
just put it there:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
$config['protocol'] = "smtp";
$config['smtp_host'] = "smtp.googlemail.com";
$config['smtp_port'] = "465"; // if you decided to use 465, then set smtp crypto to ssl, else for example 587, you need to set smtp crypto to tls.
$config['smtp_crypto'] = 'ssl'; // this is based on your smtp port -> ssl/tls
$config['smtp_timeout'] = "400";
$config['smtp_user'] = "youruser#gmail.com";
$config['smtp_pass'] = "yourpassword%&^$&$";
$config['validate'] = true;
$config['charset'] = 'utf-8';
$config['mailtype'] = "html";
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
?>
Then inside your controller you don't need to set up your $config anymore :D, but all you have to do just call $this->load->library('email'); in controller.

how to send email in codeigniter on localhost

hello all i have to send email on localhost
and following is my config file
$config['useragent'] = "CodeIgniter";
$config['mailpath'] = "/usr/sbin/sendmail -t -i";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'xyz.com'; //change this
$config['smtp_port'] = '465';
$config['smtp_user'] = 'xyz.com'; //change this
$config['smtp_pass'] = '######'; //change this
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
i create code follwing code for email send
if(count($result) > 0 || $result != NULL){
$password=$result['password'];
$this->load->library('email');
$from='chirag#site.com';
$to=$email;
$subject='forget password';
$this->email->from($from);
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($password);
if($this->email->send()){
$this->session->set_flashdata('email','We sent your password to your Email...!');
redirect('login');
}
else{
echo $this->email->print_debugger();
}
}
but i got following error when i send email
The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
so what is problem there?
please help me to solve
First make sure you already done the proper localhost configuration for sending emails.
Then in your controller you load the email library by setting the appropriate credentials and port number. Like so:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'your_gmail_name#gmail.com',
'smtp_pass' => 'your_pass',
//'mailtype' => 'html',
// 'charset' => 'iso-8859-1',
// 'wordwrap' => TRUE
);
$this->load->library('email', $config);
i got answer
there is missing a ssl:// in config
but after writing following
$config['smtp_host'] = 'ssl://xyz.com';
mail is send successfully...

mediatemple - can't send email using codeigniter

I can't send emails using mediatemple in codeigniter.I've checked the email password and smtp host and they are correct.
This is the error:
Severity: Notice
Message: fwrite() [function.fwrite]: send of 12 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host.
Filename: libraries/Email.php
Line Number: 1846
This is my code:
I have replaced sxxxxx.gridserver.com with my correct smtp.
function _sendEmail($from,$fromname,$to,$subject,$message){
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'sxxxxx.gridserver.com',
'smtp_port' => 465,
'smtp_user' => 'noreply#mywebsite.com',
'smtp_pass' => 'mypass'
);
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from($from,$fromname);
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
}
Any help would be appreciated.
Edit : I have fixed this problem using port 25.
'smtp_crypto' => 'ssl',
Add this to your config
You need to initialise the the config, see the codeigniter documentation for the email class.
Here is my example which works well...
function send_email($attributes) {
$this->load->library('email');
$this->email->set_newline("\r\n");
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'host';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'user#smtp.com';
$config['smtp_from_name'] = 'FROM NAME';
$config['smtp_pass'] = 'XXX';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from($config['smtp_user'], $config['smtp_from_name']);
$this->email->to($attributes['to']);
$this->email->cc($attributes['cc']);
$this->email->bcc($attributes['cc']);
$this->email->subject($attributes['subject']);
$this->email->message($attributes['message']);
if($this->email->send()) {
return true;
} else {
return false;
}
}

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'] = '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?
$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
According to the CI docs (CodeIgniter Email Library)...
If you prefer not to set preferences using the above method, you can
instead put them into a config file. Simply create a new file called
the email.php, add the $config array in that file. Then save the file
at config/email.php and it will be used automatically. You will NOT
need to use the $this->email->initialize() function if you save your
preferences in a config file.
I was able to get this to work by putting all the settings into application/config/email.php.
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'YOUREMAILHERE#gmail.com';
$config['smtp_pass'] = 'YOURPASSWORDHERE';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;
Then, in one of the controller methods I have something like:
$this->load->library('email'); // Note: no $config param needed
$this->email->from('YOUREMAILHERE#gmail.com', 'YOUREMAILHERE#gmail.com');
$this->email->to('SOMEEMAILHERE#gmail.com');
$this->email->subject('Test email from CI and Gmail');
$this->email->message('This is a test.');
$this->email->send();
Also, as Cerebro wrote, I had to uncomment out this line in my php.ini file and restart PHP:
extension=php_openssl.dll
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
Change it to the following:
$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "blablabla#gmail.com";
$config['smtp_pass'] = "yourpassword";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('blablabla#gmail.com', 'Blabla');
$list = array('xxx#gmail.com');
$ci->email->to($list);
$this->email->reply_to('my-email#gmail.com', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->send();
send html email via codeiginater
$this->load->library('email');
$this->load->library('parser');
$this->email->clear();
$config['mailtype'] = "html";
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('email#example.com', 'Website');
$list = array('xxxxxxxx#archmage.lk', 'xxxxx#gmail.com');
$this->email->to($list);
$data = array();
$htmlMessage = $this->parser->parse('messages/email', $data, true);
$this->email->subject('This is an email test');
$this->email->message($htmlMessage);
if ($this->email->send()) {
echo 'Your email was sent, thanks chamil.';
} else {
show_error($this->email->print_debugger());
}
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 example
# alias to postfix in a typical Postfix server
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
Then 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.
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:
$config = array(
'protocol' => '',
'smtp_host' => '',
'smtp_port' => '',
'smtp_user' => 'yourname#gmail.com',
'smtp_pass' => '**********'
);
or
$config['protocol'] = '';
$config['smtp_host'] = '';
$config['smtp_port'] = ;
$config['smtp_user'] = 'yourname#gmail.com';
$config['smtp_pass'] = 'password';
it works for me.
It can be this:
If you are using cpanel for your website smtp restrictions are problem
and cause this error. SMTP Restrictions
Error while sending an email with CodeIgniter
There is very simple answer to this . and the only solution that worked at the en was this configuration ..i only had to chnage the port to 587 and overwrite the codeignitor default "Email.php"
$config = array( 'protocol' => 'smtp', 'smtp_host' => 'smtp.gmail.com', 'smtp_port' => 587, 'smtp_user' => 'admin#cafeadmin.com.au', 'smtp_pass' => '1800#Footscray123!' );$this->load->library('email', $config);$this->email->initialize($config);

Categories