I have application where I want to send mails to clients but i am getting error from server.
Controller code for sending mail
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'mail.lmsweb.in';
$config['smtp_port'] = '25';
$config['smtp_user'] = 'support#lmsweb.in';
$config['smtp_pass'] = '****';
// $config['charset'] = 'iso-8859-1';
$this->email->initialize($config);
$this->email->from('support#lmsweb', 'LMS');
$this->email->to($this->input->post('txtvisitoremail'));
$this->email->subject('Client Login Details');
$this->email->subject('Congratulation');
$this->email->send();
echo $this->email->print_debugger();
redirect('telecaller/telecaller/update');
Same code works when using on localhost but on server I get this error.
After changing protocol to mail I get:
Message: mail() [function.mail]: SMTP server response: 503 This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.
Filename: libraries/Email.php
Line Number: 1539
I then created a new test mail account, test#lmsweb.in and tried sending mail to it and it worked. So its clear that using mail protocol I cannot send mail to other like Gmail.
I used this code to send mail from server:
function sendEmail($data, $templateName) {
//echo "<pre>";
//print_r($data);
$this->load->library('email');
$this->email->set_mailtype('html');
$this->email->from($data['from_address']);
$this->email->to($data['to_address']);
//$this->email->cc($data['cc_address']);
$this->email->subject($data['subject']);
$body = '--------'
$this->email->message($body);
$this->email->send();
$this->email->clear();
//redirect('web_welcome/member_signup');
}
In this line you don't have valid address $this->email->from('support#lmsweb', 'LMS'); You are lacking .in: support#lmsweb .in
Anyway you can use the PHP Mailer class for sending emails from codeigniter. I've done it by putting the files class.phpmailer.php and class.smtp.php in third party folder and then creating custom library for mail sending:
class Mail_sender
{
protected $ci;
var $mail;
public function __construct()
{
include (APPPATH. 'third_party/class.phpmailer.php');
$this->ci =& get_instance();
$this->mail = new PHPMailer ();
$this->init();
}
public function init(){
$this->mail->IsSMTP ();
$this->mail->IsHTML(true);
$this->mail->Mailer = 'smtp';
$this->mail->SMTPAuth = false;
$this->mail->Host = 'smtp.t-home.mk'; // "ssl://smtp.gmail.com" didn't worked
$this->mail->Port = 25;
$this->mail->SMTPSecure = '';
$this->mail->SMTPAuth = true;
$this->mail->Username = 'user#example.com'; // SMTP username
$this->mail->Password = 'secret'; //SMTP password
$this->mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.
}
public function setUsername($username){
$this->mail->Username = $username;
}
public function setFrom($email, $sender_name) {
$this->mail->From = $email;
$this->mail->FromName = $sender_name;
}
public function setAddress($to){
$this->mail->addAddress ($to);
}
public function setReplyTo($replyTo)
{
$this->mail->AddReplyTo($replyTo);
}
public function setSubject($subject){
$this->mail->Subject = $subject;
return $this->mail->Subject;
}
public function setBody($messageBody){
$this->mail->Body = $messageBody;
}
public function sendMail(){
return $this->mail->Send();
}
}
And used a controller for sending mail:
$nameSurname=$this->input->post('name');
$email = $this->input->post('email');
$subject = $this->input->post('subject');
$temp_message = $this->input->post('message');
$message = 'FROM: '.$nameSurname.'('.$email.')<br><br>'.$temp_message;
$array = array(
'ime' => $nameSurname,
'mail' => $email,
'sub' => $subject,
'msg' => $message
);
$this->load->library('mail_sender');
$this->mail_sender->setFrom('[from address]','[title]');
$this->mail_sender->setSubject($subject);
$this->mail_sender->setAddress("[receiving address]");
$this->mail_sender->setBody($message);
$this->mail_sender->sendMail();
Hope it helps.
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'something#mail.com', // change it to yours
'smtp_pass' => '*******', // change it to yours
'wordwrap' => TRUE,
'crlf' => "\r\n",
'newline' => "\r\n" );
it is worked for me after adding last two lines ''crlf' => "\r\n",
'newline' => "\r\n"'
Related
<?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);
<?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);
I am trying to send email from live server using domain email id. I tried with different port id, every time I got same error.My controller code is given below:
public function send_mail() {
$this->load->library('email');
$name = $this->input->post("name");
$email = $this->input->post("email");
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'mail.*******.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'info#*******.com';
$config['smtp_pass'] = '*********';
$config['charset'] = 'utf-8';
$config['newline'] = '\r\n';
$config['mailtype'] = 'text'; // or html
$config['validation'] = TRUE;
$this->email->initialize($config);
$this->email->from('info#*******.com', 'Hima');
$this->email->to($email);
$this->email->subject('email verification');
$this->email->message('Verification Code');
$send = $this->email->send();
if ($send) {
$this->session->set_flashdata('msg','success');
} else {
echo $error = $this->email->print_debugger();
}
}
I have configured like following :
public function send_mail() {
$this->load->library('encrypt');
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => '465',
'smtp_user' => '*****#gmail.com',
'smtp_pass' => '**********',
'smtp_crypto' => 'ssl',
'crlf' => "\r\n",
);
$this->load->library('email',$config);
$send = $this->email->send();
if ($send) {
return $send;
} else {
$error = show_error($this->email->print_debugger());
return $error;
}
}
Hope this helps!
I have created a controller and made a test function in the controller to test if the email is sent or not.
I checked with different email addresses, but didn't succeed. This is my code example:
public function sendmail() {
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$user_id = 1;
$name = 'Mark Alan';
$this->email->set_newline("\r\n");
$this->email->from('info#domainname.com', "Test Name");
$this->email->to('test#domainname.com');
$this->email->subject('Test Mail');
$this->email->message('This is a test message');
$this->email->send();
echo $this->email->print_debugger();
}
With Codeigniter (assuming you have auto-loaded the email library) you can either set an email preference in a config file, named email.php and these preferences are loaded automatically from there. It could look like:
// Setting Email Preferences
$config['useragent'] = 'CodeIgniter'; // Mail engine switcher: 'CodeIgniter' or could be 'PHPMailer'
$config['protocol'] = 'smtp'; // 'mail', 'sendmail', or 'smtp'
$config['mailpath'] = '/usr/sbin/sendmail';
or like in your example, you can set them manually, but need to initialize it, so don't forget this line after defining your $config[] array:
$this->email->initialize($config);
Try this code:
function sendMail()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com', //Your Host
'smtp_port' => 465, // Add 25 port if you sending from your smtp mail server
'smtp_user' => 'xxx#gmail.com', // change it to yours, server email
'smtp_pass' => 'xxx', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = '';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxx#gmail.com'); // change it to yours
$this->email->to('xxx#gmail.com');// change it to yours
$this->email->subject('Resume from JobsBuddy for your Job posting');
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
Note: Please add your smtp port and your smtp email account detail.
<?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);