fsockopen error after upgrading to php 7 - php

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

Related

Not able to send email - Codeigniter

I am unable to send email via following configuration.
$config = array();
$config['protocol'] = 'smtp';
$config['mailtype'] = 'text';
$config['charset']='utf-8';
$config['crlf']="\r\n";
$config['newline']="\r\n";
$config['priority']=3;
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_port']=587;
$config['smtp_crypto']="tls";
$config['smtp_user'] = '************';
$config['smtp_pass'] = '************';
$config['smtp_timeout'] = 120;
$this->email->initialize($config);
$this->email->set_newline("\r\n");
I have checked millions of blog and articles.
Same configuration is working properly on production but not on staging environment.
Following error is generated:
Message: stream_socket_enable_crypto(): SSL: Handshake timed out
$config['smtp_host'] = 'smtp.office365.com';
change to
$config['smtp_host'] = 'ssl://office365.com';
Have you check to enable Open SSL module in php.ini?
If not then check the points below.
Open your php.ini file
Search this line: ;extension=php_openssl.dll
Enable the module by removing ; char.
Save the file and restart Apache.
Then do check. This may help you.

Error when calling send method in Codeigniter email library

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";
:)

sending email via gmail smtp server with codeigniter

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

CodeIgniter + MAMP : unable to send emails

I am trying to send emails with CI running on MAMP free. But it doesn't work, my script is encountering an infinite loop and nothing is happening...
Do i need to set up something especially to send emails from localhost?
Here is my email config for CI:
$config = array();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = '*****#gmail.com';
$config['smtp_pass'] = '******';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = '\r\n';
Cheers
EDIT: Here is my code to send an email:
$config = array();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = '****';
$config['smtp_pass'] = '*****';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = '\r\n';
$this->email->initialize($config);
$this->email->from('****');
$this->email->to($email);
$this->email->subject($title);
$this->email->message($content);
$this->email->send();
error_log($this->email->print_debugger());
With $title, $content and $email vars defined in another part of my script. Don't worry about this stuff, I've already checked that my issue is not due to these.
Finally I found the solution:
Send emails with MAMP (mail() PHP function)
Set up SSL: http://soundsplausible.com/2012/01/14/enable-ssl-in-mamp-2-0-5/
Set up Postfix: http://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-mountain-lion/
Into MAMP's php.ini (glance phpinfo() to know which version is used and conclude into which folder you need to edit), comment lines SMTP, smtp_port and sendmail_from. Uncomment line sendmail_path and set /usr/sbin/sendmail -t -i as new value.
You should be able to send emails now, if PostFix works fine (run test given in tutorial above).
Send emails with CI
To send emails with CI, you don't need to write your logins into a file for PostFix. However, you need to be able to run PostFix and SSL.
Here is an example of config file for a google account:
$config['protocol'] = "smtp";
$config['smtp_host'] = "smtp.gmail.com";
$config['smtp_port'] = "587";
$config['smtp_user'] = "*****";
$config['smtp_pass'] = "*****";
$config['smtp_crypto'] = "tls"; //very important line, don't remove it
$config['smtp_timeout'] = "5"; //google hint
$config['mailtype'] = "text";
$config['charset'] = "utf-8";
$config['newline'] = "\r\n";
Be careful with " " which are necessary, ' ' could create issues. Here I'm using a TLS connection. If you prefer SSL, use port 465 and fix correctly smtp_crypto value.
You need use sendmail(details how install it on MAMP). Or you can use solution below to store emails in localhost(something like emulate email sending).
I'm use this solution on my localhost(XAMPP). Maybe it will be helpful for you.
Specify path for send mail in php.ini
sendmail_path = "path/to/php path/to/sendmail.php"
The second step - you can try to use this script
define('DIR','path/to/sendmail_dir');
$stream = '';
$fp = fopen('php://stdin','r');
while($t = fread($fp,2048)){
if($t === chr(0)){
break;
}
$stream .= $t;
}
fclose($fp);
$fp = fopen(mkname(),'w');
fwrite($fp,$stream);
fclose($fp);
function mkname($i=0){
$fn = DIR.date('Y-m-d_H-i-s_').$i.'.eml';
if (file_exists($fn)){
return mkname(++$i);
}
else{
return $fn;
}
}

Codeigniter not connecting to my SMTP server

For some reason CodeIgniter is not connecting to my SMTP server, anyone have any problems surrounding this?
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.netregistry.com.au';
$config['smtp_port'] = '465';
A PHP Error was encountered
Severity: Warning
Message: fsockopen(): unable to connect to smtp.netregistry.com.au:465 (php_network_getaddresses: getaddrinfo failed: Name or service not known)
Filename: libraries/Email.php
Line Number: 1689
Should I be using the SSL or non-SSL port? (I've tried both; no dice)
Is there a way of explicitly telling CI to use SSL or not?
Am I doing anything blaringly wrong here?
Thanks
The smtp server was actually incorrect.
From the error, it said "getaddrinfo failed: Name or service not known".
And the function php_network_getaddresses shoots the error.
That might means your SMTP server is behind your company gateway, or is a private server.
So, that results in fsockopen() doesn't seem to find your SMTP server.
Try to run your code again in your company, that should work then.
You could try putting ssl: in the host address:
$config['smtp_host'] = 'ssl://smtp.netregistry.com.au';
$config['smtp_port'] = '465';
Quite often smtp hosts have security in place that prevents this kind of use. Have you tried using a gmail account? That does work for me, here is how I use it:
function send_email($attributes) {
$this->load->library('email');
$this->email->set_newline("\r\n");
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'xxx#gmail.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;
}
}
there will be system/libraries/Email.php file.
default port will be 25 .please also add smtp_host as localhost there like this..
var $smtp_host = "localhost";
var $smtp_port = "25";

Categories