I have been been trying send email by using gmail smtp server on codeigniter framework.
it working perfect testing on localhost . When I test it on server I got 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: 1689 "
my code is
$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "ticket#gmail.com";
$config['smtp_pass'] = "test123";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('sender#gmail.com', 'Myanmar Bus Ticket');
$list = array('receiver#gmail.com');
$ci->email->to($list);
$ci->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();
highly appreciate for all of your help
I have found the following:
To use Google SMTP in CodeIgniter you need to make 2 (two) changes into your Gmail account setting: (N.B. Please be aware that it is now easier for an attacker to break into your account -says Google)
Set off 2-step Verification.
Allow less secure apps: ON (or Enable)
Now use 'smtp_host' as ssl://smtp.gmail.com instead of smtp.googlemail.com
Hope this will help upcoming visitor.
Create a file in application/config/email.php with the following:
<?php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com'; //examples: ssl://smtp.googlemail.com, myhost.com
$config['smtp_user'] = 'user#gmail.com';
$config['smtp_pass'] = 'password';
$config['smtp_port'] = '465';
$config['charset']='utf-8'; // Default should be utf-8 (this should be a text field)
$config['newline']="\r\n"; //"\r\n" or "\n" or "\r". DEFAULT should be "\r\n"
$config['crlf'] = "\r\n"; //"\r\n" or "\n" or "\r" DEFAULT should be "\r\n"
?>
Related
I want to send email using Amazon SES in Codeigniter, i have tried everything, i also tried the earlier questions asked on codeigniter too, but i am not able to find the solution for this.
public function add_applicants()
{
$this->load->model('visa/India_model');
$datan = $this->India_model->insertappdata();
$appid = $datan[appid];
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['charset'] = 'ISO-8859-1';
$config['mailtype'] = 'html';
$config['smtp_host'] = "ssl://email-smtp.eu-west-1.amazonaws.com";
$config['smtp_user'] = "SMTP USER SES";
$config['smtp_pass'] = "SMTP Password SES";
$config['smtp_port'] = "465";
$config['newline'] = "\r\n";
$config['mailsender'] = "support#indiaevisaservice.com";
$config['smtp_crypto'] = 'tls';
$this->email->initialize($config);
$this->email->print_debugger();
$this->email->from('support#verfiedemail.com', 'GYEV Experts');
$this->email->to('imthegrv#gmail.com', 'Test To');
$this->email->subject('Test');
$this->email->message('test');
if($this->email->send()):
print_r($appid);
else:
print_r($this->email->print_debugger());
endif;
}
i am getting error
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
You didn't follow the link provided in the error message, which provides tests that you can use to diagnose your problem.
These three lines are inconsistent:
$config['smtp_host'] = "ssl://email-smtp.eu-west-1.amazonaws.com";
$config['smtp_port'] = "465";
$config['smtp_crypto'] = 'tls';
tls mode will not work on port 465. That should be ssl. Alternatively, change port to 587, and it should be an integer, not a string. There's also no need for the ssl:// prefix on your host; that just adds confusion. First step, change them to this:
$config['smtp_host'] = 'email-smtp.eu-west-1.amazonaws.com';
$config['smtp_port'] = 465;
$config['smtp_crypto'] = 'ssl';
You may still have other issues (e.g. your ISP may block outbound SMTP connections), but there are many other tests listed in the guide that will help you diagnose that.
I have the following code for sending email using codeigniter email library using SMTP using office365 SMTP
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_user'] = 'xxxxxx#example.com';
$config['smtp_pass'] = '123456';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['smtp_port'] = 587;
$config['smtp_timeout'] = 60;
$config['smtp_crypto'] = 'tls';
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from('xxxxxx#example.com');
$this->email->to('test123#gmail.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->set_mailtype('html');
$this->email->set_newline("\r\n");
$this->email->send();
And it shows an error
Failed to send AUTH LOGIN command. Error: 504 5.7.4 Unrecognized
authentication type [SG2PR0601CA0010.apcprd06.prod.outlook.com]
Unable to send email using PHP SMTP. Your server might not be
configured to send mail using this method.
In office365,shows configuration like bellow
NOTE: It is using office365 SMTP not gmail
Just use this line of code in your config file code:
$config['protocol'] = 'sendmail';
instead of
$config['protocol'] = 'smtp';
Hopefully, it will solve the error.
I have the below code for sending email, and on this I am getting SMTP error.
The following SMTP error was encountered: 10060 A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Unable to send data: AUTH LOGIN
It is a very long error I have just provided the upper part.
CODE.
$frommail = "sharadrsoni#gmail.com";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'sharadrsoni#gmail.com';
$config['smtp_pass'] = 'pass'; //your smtp password
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$this->email->initialize($config);
$this->email->from($frommail, $companyfullname);
$this->email->to($tomail);
$this->email->subject($subject);
$this->email->set_mailtype('html');
$this->email->message($MHtml);
$emailSent = $this->email->send();
I have tried couple of ways but ended showing this error only.
I am using CodeIgniter version: 2.1.0
Edited:
Im trying to send an email using codeigniter's library. Whenever I call the $this->email->send() function it returns
Warning: include(C:\xampp\htdocs\psems\application\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\xampp\htdocs\psems\system\core\Exceptions.php on line 269
Warning: include(): Failed opening
'C:\xampp\htdocs\psems\application\views\errors\html\error_php.php'
for inclusion (include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\psems\system\core\Exceptions.php on line 269
This is the code I have so far
$config = array();
$config['useragent'] = "CodeIgniter";
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "smtp";
$config['smtp_host'] = "localhost";
$config['smtp_port'] = "25";
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$this->load->library('email');
$this->email->initialize($config);
$this->email->from('example#gmail.com', 'harold decapia');
$this->email->to('example#gmail.com');
$this->email->subject('Тест Email');
$this->email->message('Hello World');
$this->email->send(); //I tried commenting this out and there was no error returned
I'm confused as to why it returns an error just by calling the send method. Do I have to configure something first? I'm thinking I'm missing a tiny bit of info here :(
Also, is there any way for me to know what error it returns specifically? Thank you in advance
The error as far as I can see it's coming because you're trying to send an email with SMTP on a server without and actual FTP server (Happens a lot with local servers).
I'm going to suggest a free service like Mailgun to use as an SMTP server while you're developing.
Also if you're going to use SMTP protocol, you'll need to use an User and Password to authenticate on the SMTP server (Mailgun will provide you with that too).
Here it's a sample of the new configurations for the SMTP server/authentication, remember you need to adjust to the information the Mailgun website will give you on your account.
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.mailgun.org';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '30';
$config['smtp_user'] = 'postmaster#mydomain.com';
$config['smtp_pass'] = 'password';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
:)
I run codeigniter3.03 on digital ocean nginx and php 7. When I try to send an email I get this error:
Code:
Severity: Warning
Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out)
Filename: libraries/Email.php
Line Number: 1986
My email setup is
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'xxxxxx#gmail.com';
$config['smtp_pass'] = 'xxxxxxxxxxxx';
$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;
This version runs flawlessly in the same config under php 5.x.
in php.ini i have
extension=php_openssl.dll
enabled.
I could not get any hint anywhere why this should not work in php7. Can anybody give me a hint what to check or what the cause of this error could be.
Did you try smtp.googlemail.com already?
Also note this other answer, with a working example (seems to be different, for instance in the timeout definition):
phpmailer send gmail smtp timeout
Another solution:
Having trouble with PHPMailer