I want send a email by Email Class in codeigniter with gmail, but i get following error:
Error:
A PHP Error was encountered Severity: Warning Message:
mail() [function.mail]: Failed to connect to mailserver at
"ssl://smtp.googlemail.com" port 25, verify your "SMTP" and
"smtp_port" setting in php.ini or use ini_set() Filename:
libraries/Email.php Line Number: 1553
This is my full function in controll:
function send_mail(){
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'xyz#gmail.com';
$config['smtp_pass'] = 'xxxxxxx';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('neginph#gmail.com', 'Negin Phosphate Shomal');
$this->email->to('neginfos#yahoo.com');
$this->email->subject('This is an email test');
$this->email->message('It is working. Great!');
if($this->email->send())
{
echo 'Your email was sent, successfully.';
}
else
{
show_error($this->email->print_debugger());
}
}
I changed SMTP in php.ini as this:
SMTP = ssl://smtp.googlemail.com smtp_port = 25
What do i do?
With respect
this is what worked for me
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'someuser#gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email', $email_config);
$this->email->from('someuser#gmail.com', 'invoice');
$this->email->to('test#test.com');
$this->email->subject('Invoice');
$this->email->message('Test');
$this->email->send();
Have you turned on php_openssl?
Try to uncomment extension=php_openssl.dll in your php.ini file.
This is working for me on localhost:
<?php
class Email extends CI_controller
{
function index()
{
$this->load->library('email');
$this->load->helper('url');
$this->load->helper('form');
$config= Array(
'protocol' =>'localhost',
'smtp_host' => 'localhost',
'smtp_port' => 'localhost',
'smtp_user'=> 'root',
'smtp_pass' =>''
);
$this->load->library('email','$config');
$this->email->set_newline("\r\n");
$this->email->from('nisha#gmail.com','nisha');
$this->email->to('cse1473#gmail.com');
$this->email->subject('this is email with subject');
$this->email->message('it s working properly');
if($this->email->send())
{
echo "your email send";
}
else
{
show_error($this->email->print_debugger());
}
}
}
?>
Related
I have use gmail smtp email library to send mail from codeingiter project.
But it shows below error while submit form:
A PHP Error was encountered
Severity: Warning
Message: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Filename: libraries/Email.php
Line Number: 1902
Backtrace:
File: D:\xampp\htdocs\projectName\application\controllers\Users.php
Line: 66
Function: send
File: D:\xampp\htdocs\projectName\index.php
Line: 315
Function: require_once
My controller function code:
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 587, //if 80 dosenot work use 24 or 21
'smtp_user' => '**',
'smtp_pass' => '**',
'_smtp_auth' => true,
'smtp_crypto' => 'tls',
'protocol' => 'smtp',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('users#gmail.com'); //same email u use for smtp_user
$this->email->to($this->input->post('user_email'));
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
My php.ini file:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP=localhost
; http://php.net/smtp-port
smtp_port=25
But still mail not send.
Is there any problem with my controller.
The issue with your code is that you are not initializing the email setting. Your controller code on line $this->load->library('email', $config); is wrong. You have to initialize the email setting separately after the email library is loaded.
Take a look at this code.
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_port'] = 587, //if 80 dosenot work use 24 or 21
$config['smtp_user'] = '**';
$config['smtp_pass'] = '**';
$config['_smtp_auth'] = true,
$config['smtp_crypto'] = 'tls';
$config['protocol'] = 'smtp';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE
$this->load->library('email');
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('users#gmail.com'); //same email u use for smtp_user
$this->email->to($this->input->post('user_email'));
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
For more information look at here
I am using godaddy shared hosting is there and of what i read that it's not possible to send emails using SMTP from a shared hosting is there any alternative way .. i am trying to send emails using codeigniter but it's not working at all
$this->email->clear();
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to($user->email);
$this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_forgotten_password_subject'));
$this->email->message($message);
if ($this->email->send())
{
$this->set_message('forgot_password_successful');
return TRUE;
}
else
{
$this->set_error('forgot_password_unsuccessful');
return FALSE;
}
Check: GoDaddy POP and SMTP Server Settings
Check the library configuration email, and your hosting provider looking email accounts created, select and view a manual configuration.
Documentation Codeigniter Email
<?php
public function sendEmailSMTP(){
$this->load->library("email");
$configEmail = array(
'useragent' => "CodeIgniter",
'mailpath' => "/usr/bin/sendmail", // or "/usr/sbin/sendmail"
'protocol' => 'smtp',
'smtp_host' => 'URL',// URL check: http://www.yetesoft.com/free-email-marketing-resources/godaddy-pop-smtp-server-settings/,
'smtp_port' => 465, // Usually 465
'smtp_crypto' => 'ssl', // or tls
'smtp_user' => 'youremail#yourdomain.com',
'smtp_pass' => 'AccountPasswordEmail',
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => "\r\n"
);
//Load config
$this->email->initialize($configEmail);
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to($user->email);
$this->email->subject(($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_forgotten_password_subject'));
$this->email->message($message);
$this->email->send();
// See result
echo $this->email->print_debugger();
} // End sendEmailSMTP()
I'm try to sending email using SMTP server with codeIgniter
i have code and its working fine on localhost but not on server, i have done lots of research and try many code but it's still not working.
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxxx#gmail.com',
'smtp_pass' => 'xxxxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxx#gmail.com', 'Blabla');
$list = array('xxx#gmail.com','xxxxx#gmail.com');
$this->email->to($list);
$this->email->reply_to('xxxxx#gmail.com', 'Explendid Videos');
$this->email->subject('This is an email test');
$this->email->message('It is working. Great!');
$result = $this->email->send();
Error-
The following SMTP error was encountered: 111 Connection refused
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
please edit your autoload to
$autoload['libraries'] = array('database','email');
please advise if you are still getting an error...
I am trying to send email using codeigniter.
<?php
class email_page extends CI_Controller{
function __construct(){
parent::__construct();
}
function index(){
$config = Array(
'protocol'=>'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'testmail#gmail.com',
'smtp_pass' => 'password'
);
$this->load->library('email', $config);
$this->email->set_newline('\r\n');
$this->email->from('testmail#gmail.com','Sender name');
$this->email->to('testmail#gmail.com');
$this->email->subject('Test mail');
$this->email->message('This is a test mail from codeigniter');
if($this->email->send()){
echo "Your mail was sent successfully!!!";
}
else{
show_error($this->email->print_debugger());
}
}
}
The page keeps on loading and does not give any result. The code looks fine to me. Are there any errors? Thanks
change your account settings here
https://www.google.com/settings/security/lesssecureapps
I myself found the answer.
$this->email->set_newline('\r\n');
Changed the above line to
$this->email->set_newline("\r\n");
I am not sure how this can happen.
i have found error, just change port to 25
function test(){
$config = Array(
'protocol'=>'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => '25',
'SMTPAuth' => true,
'smtp_user' => 'email#gmail.com',
'smtp_pass' => 'password'
);
$this->load->library('email', $config);
//$this->email->set_newline('\r\n');
$this->email->from('email#gmail.com','Sender name');
$this->email->to('email#micromerger.com');
$this->email->subject('Test mail');
$this->email->message('This is a test mail from codeigniter');
//print_r($this->email);exit;
if( ! $this->email->send()){
//print_r("234");exit;
echo "Your mail was sent successfully!!!";
}
else{
//print_r("345");exit;
show_error($this->email->print_debugger());
}
}
I am using codeigniter for my web application and i use the codeigniter's email functionality to send email. But I occurred the following error when i try to send the email.
Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP
This is the code i used to gain the functionality.
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.googlemail.com";
$config['smtp_port'] = 465;
$config['smtp_user'] = "xxxx#gmail.com";
$config['smtp_pass'] = "xxxxxx";
$this->load->library('email');
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('xxxx#gmail.com','Sample');
$this->email->to('xxxxx#gmail.com');
$this->email->subject('temperary Email');
$this->email->message('This is a sample message');
if ($this->email->send()) {
echo 'Your email was sent, dude.';
} else {
show_error($this->email->print_debugger());
}
What is wrong with this?
Thanks..
Open ssl should be enabled.
have a look here http://www.devcha.com/2010/01/php-fsockopen-unable-to-connect-ssl.html
Or you can load the parameter in array:
$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();
This works for me
I had some "crazy" problems using the CI´s default email library to send emails through SSL/TLS authenticated SMTP servers. I ended up using PHPMailer instead.