i have an error by trying to send an email using codeigniter email Class.
I have an error of :
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
How can i test to send email in codeigniter?. I am also using localhost. Is this problem only occurs when i use localhost?
Here is my code:
public function emailme() {
$this->load->library('email');
$message = $this->input->post('email_msg');
$this->email->from('iamjohnx3303#yahoo.com', 'John');
$this->email->to('iamjohnx3302#gmail.com');
$this->email->subject('Email Test');
$this->email->message($message);
$this->email->send();
}
Configuration in sendmail.ini
path c:\xampp\sendmail\sendmail.ini
Configurations
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail#gmail.com
auth_password=yourgmailpassword
force_sender=myemail#gmail.com
in php.ini
pathc:\xampp\xampp\php\php.ini
[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
then
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx#gmail.com',// your mail name
'smtp_pass' => '*****',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
'wordwrap' => TRUE
);
$this->load->library('email', $config);
Mail Settings in XAMPP(Important)
$this->email->from('mygmail#gmail.com', 'myname');//your mail address and name
$this->email->to('target#gmail.com'); //receiver mail
$this->email->subject('testing');
$this->email->message($message);
$this->email->send(); //sending mail
Use this before your send mail script
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.YourDomain.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'ValidEmailAccount#YourDomain.com');
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
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have a problem like this.I want to send a mail from my web application so I put this in my controller.
$from_email = "tharuwan40#gmail.com";
$to_email = "warimali94#gmail.com";
//Load email library
$this->load->library('email');
$this->email->from($from_email, 'Info');
$this->email->to($to_email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
This web application is still running on localhost.I tried so many examples in the net and which have been posted in stack overflow tooo.But there was nothing on my mail.Email was not send.How can I get fix this?
Create config array
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx#gmail.com',// your mail name
'smtp_pass' => '*****',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
'wordwrap' => TRUE
);
then
$this->load->library('email', $config);
$this->email->from('mygmail#gmail.com', 'myname');//your mail address and name
$this->email->to('target#gmail.com'); //receiver mail
$this->email->subject('testing');
$this->email->message($message);
if($this->email->send()) //sending mail
{
echo 'Mail sent';
}
else
{
print_r($this->email->print_debugger(), true);
}
Configuration in sendmail.ini
path [xampp folder]\sendmail\sendmail.ini
Configurations
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail#gmail.com
auth_password=yourgmailpassword
force_sender=myemail#gmail.com
open php.ini config file and search for[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Restart Server
Main Source
I will try to send mail using gmail in codeigniter. I write code as given bellow. When i upload it on c panel it will work properly for 2 days but after that it stop working.
//Load email library
$this->load->library('email');
//SMTP & mail configuration
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxxxx',
'smtp_pass' => 'xxxxxx',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_mailtype('html');
$this->email->set_newline("\r\n");
//Email content
$htmlContent = '<h1>MY WEBSITE</h1>';
$htmlContent .= '<p>OTP For Reset Your Password.</p>';
$this->email->to($uemail);
$this->email->from('xxxxxxxx','MyWebsite');
$this->email->subject('MESSAGE');
$this->email->message($htmlContent);
//Send email
$this->email->send();
I experienced the same thing where the email was not sent and there was no error, it turned out that when I checked my Gmail account it wasn't always on the Primary tab (make sure it wasn't in the Spam folder either). Sent but in the Promotions tab.
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 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());
}
}
}
?>