In PHP, I am getting this error while sending email:
"fsockopen() [function.fsockopen]: unable to connect to tls://smtp.gmail.com:465 (Connection timed out)".
Can anyone help me to dynamically load openssl.ddl extention through .htaccess file or any other means other than dl().
I am working with Yii and this is how my main.php is:
'mail' => array(
'class' => 'application.extensions.yii-mail.YiiMail',
'transportType'=>'smtp', /// case sensitive!
'transportOptions'=>array(
//'host'=>$smtp_host,
'host'=>'smtp.gmail.com',
//'username'=>$smtp_username,
'username'=>'mailtest.test10#gmail.com',
//'password'=>$smtp_password,
'password'=>'testtest10',
//'port'=>'543',
'port'=>'465',
'encryption'=>'tls',
//'encryption'=>'ssl',
),
'viewPath' => 'application.views.mail',
'logging' => true,
'dryRun' => false
),
can anyone please let me know where I am wrong....
I solved my problem. Actually this configuration was working in localhost but was giving error in server. Had to change settings to work in server. Changed host value to localhost and changed the username and password to same as in server settings. It is working now.
Related
Greetings to the community!
I have recently developed a web page with Laravel 9.X, which works correctly in local, but when I upload it to my Host, I am having problems with sending emails.
When I have been testing locally, it has been working correctly, and I have been using mailtrap. Now that I have uploaded it to the server, I have my own SMTP, and it is not working for me. I have the ssl certificate created, but there is no way it will send me any mail. I get the following error:
Unable to connect with STARTTLS: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed.
SSL working fine when i visit the site with https.
I have configured my .env file, where I have put:
HOST: my smtp server; PORT: 587; ENCRYPTION TYPE: SSL; USERNAME AND PASSWORD: Those of my email account.
I have been touching also my file located in config/mail.php, putting the same configuration as in the .env file. I have also tried with other ports like 25, 465... among others.
I have tried to access the mail account from outlook, using the IMAP protocol, and I have been able to connect correctly, so the mail can be accessed.
I have checked lot of things in Google, and also every blogs y found in Stack Overflow, but nothing worked.
Any idea what is going on?
Am I missing something to configure?
I had this problem after upgrading to the new 9 version, so you need to follow two steps.
Edit your .env file located in the root of the project The place where your mail settings are described, change tls to null. If you do not have such a line, then add
MAIL_ENCRYPTION=null
If you have version 8 then this will be enough, but in version Laravel 9 you will need to open the file app/config/mail.php Find a section mailers smtp add two options 'auth_mode' => null and 'verify_peer' => false an example of how it would look
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
'verify_peer' => false,
],
I know this question is asked many times and have different solutions and I have tried all but no one has worked. This is my settings.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=abc#mydomain.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
And application is currently running on Centos 7 OS.
I always get
Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [Connection timed out #110]
at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'ssl', 'host' => 'smtp.gmail.com', 'port' => '465', 'timeout' => '30', 'blocking' => '1', 'tls' => false, 'type' => '1', 'stream_context_options' => array())) in AbstractSmtpTransport.php line 113
I have tried all solutions, by Replacing: smtp.gmail.com with 173.194.65.108, or replacing smtp.gmail.com by gmail-smtp-msa.l.google.com. When I do these two steps, it got server not found error.
If I change mail driver from smtp to sendmail or mail, no error is thrown but no email is sent.
If I use ip address of smtp.gmail.com, I got same result. If I change port from 465 to 587 and encryption from ssl to tls, nothing happens.
I have also created a file in etc/gai.conf and put precedence ::ffff:0:0/96 100. It worked one time. But later after two hours, it stopped working and started throwing same error.
I have also tried using my gmail id but all in vain.
The only solution that I couldn't be able to test is verifying httpd_can_sendmail as whenever I run command getsebool httpd_can_sendmail I get getsebool: SELinux is disabled. Is this the problem or is there any other way to get it fixed?
Here is my working mail config file:
return [
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => ['address' => '*******#gmail.com', 'name' => '****'],
'encryption' => 'tls',
'username' => '*******#gmail.com',
'password' => '*******',
'sendmail' => '/usr/sbin/sendmail -bs',
];
but from your question i can see you already tried all this, so i can assume it is a network problem based on error 'connection time out', what i mean is that something is blocking your connection, it might be your firewall if you have.
so first you should check that the port 587 is open, or you can check if other application can connect with smtp.gmail.com (don't know how to do it in centOs).
And at last this might not be a problem but you have to enable 'Allow less secure apps' in your google account just for testing. (This is not permanent solution but for testing, if it works then you should enable two step verification in google account and then create new application, you can create new special password which you can use as your password for smtp server)
In my case it was necessary to clear config cache to pull up .env file new settings
php artisan config:cache
Since you are using gmail, but I don't know what password you are setting, the MAIL_PASSWORD variable must be the same as the gmail application password. In this case, Gmail provides a third-party application service so that these, (in this case your application), can send emails using this type of authentication.
I transfer my application from Laravel 4 to Laravel 5, in sending email particularly in (reset Password).. I got this error
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL
Error messages: error:14090086:SSL
routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
but in laravel 4, it works.
I faced similar problem so I set
MAIL_ENCRYPTION= in .env file.
and it worked fine for me.
This error means that the SSL certificate verification is failing.
A quick fix would be to add to StreamBuffer.php these lines right after the condition:
if (!empty($this->_params['sourceIp']))
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
If you are using basically Windows for development this is the common problem.
Changing your mail driver to "mail" from "smtp" will help.
you can use google app password ,for me it worked after changing the gmail password with app password you can do that by visiting my account>sign in>
Go to location \vendor\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php en la linea 259.Comment the following:
//$options = array();
and add.
$options['ssl'] = array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true);
:D!
Add
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
));
before
mail->send()
and replace
require "mailer/class.phpmailer.php";
with
require "mailer/PHPMailerAutoload.php";
That's an error with your SSL certificate. You are trying to use a SSL connection (encrypted, secure connection) without a proper certificate.
That's because you are connecting from localhost, which is not secure, and that is blocked by the connection. You could avoid that by changing your localhost connection to a SSL based one.
Also check and add below code in 'config/mail.php' this file.
'stream' => ['ssl'=>
['allow_self_signed'=>true, 'verify_peer'=>false, 'verify_peer_name'=>false]
],
I having one yii app hosted on godaddy windows hosting server,
All db config is ok but i am facing one error as **CDbException
CDbConnection failed to open the DB connection.**
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=my_db_name',
'emulatePrepare' => true,
'username' => 'myusername',
'password' => 'mypassword',
'charset' => 'utf8',
'tablePrefix' => 'tbl_'
),
all host name dbname username and pasword is correct then also i am facing with this error.
If someone have all ready solved this problem of hosting yii app on godaddy windows server please help me....
Thank you in advance..
Does the error message continue with "could not find driver?" Godaddy has PHP's PDO extension disabled on its Windows boxes (see here). Fastest solution were to change your hosting plan to Linux.
I understand this problem has been a recurring problem on this site, but my issue is a little different than the previous ones.
PROBLEM
Some pages use the correct socket directory, while other pages try and connect through an incorrect socket directory or this is what I believe the problem is based on the error i am receiving.
DETAILS
HOST: example.com
cakePHP version: 1.3.2 (Not my choice).
Page's content comes from database.
URL: http://example.com
My website has 2 sections:
anonymous section
login section for members or admin
The anonymous section works. It accesses the database, adds the content, and funcitons as it should.
ERROR
The error occurs when I click a link "view more.." under "Job Links" on the home page. A login form should pop up, instead i receive the error "cannot connect to local MySql server through socket '/var/run/mysqld/mysqld.sock' (2)".
In addition, after I login via the "Members login" button, also on the home page, with the correct credentials, it also produces the same error.
QUESTION
Why would different sections on my webpage try to access the sockets through different directories?
ADDITIONAL STUFF
I signed up today and this is my first post, so feedback on my post regarding enough information would be helpful for future posts.
Thanks for your time.
UPDATE
Upon further research, MySql has been using the socket directory /var/run/mysqld/mysqld.sock from the start. Not sure what this means yet, but continuing research..
database.php file
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysqli',
'persistent' => true,
'host' => 'redlabelcom.netfirmsmysql.com',
'login' => 'bcp',
'password' => '********',
'database' => 'bcp',
'prefix' => '',
'encoding' => 'UTF8',
//'socket' => '/var/run/mysqld/mysqld.sock', // I've tried commenting out all variations of socket and port
//'port' => '/var/run/mysqld/mysqld.sock', // nothing works.
);
var $test = array(
'driver' => 'mysqli',
'persistent' => false,
'host' => 'redlabelcom.netfirmsmysql.com',
'login' => 'bcp',
'password' => '********',
'database' => 'bcp',
'prefix' => '',
'encoding' => 'UTF8',
//'port' => '/var/run/mysqld/mysqld.sock',
);
}
?>
This problem is really strange. I guess this has something to do with mysql connection. MySQL is a daemon, usually configured in /etc/mysql/my.cnf. There you define how the client will connect the MySQL server:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
If your socket is wrong (there's no such socket on the server), you are probably connecting different mysql host/port from anonymous/secured parts of application. This is possible (I mean different db connections from different application parts). Check your configuration (host, port, etc.) and try to connect from MySQL console:
$ mysql -h hostname -u username -p dbname # enter password
and check if you can connect. If you can connect from console, you'll surely connect from any server-side application (php, python, whatever).
It's an application that someone else was developing, right, and now you have to maintain it?
PROBLEM SOLVED!
Thanks everyone for your support!
This was an interesting issue that initially looked more complicated than the actual problem.
cakephp version 1.3.2 is set up to make a new connection to the database if you need to access the phpbb data fields. The new connection uses a different configuration than what is set up in the database.php file.
Below is a detailed description with file locations.
the 'app/webroot/discussion/common.php' file makes a NEW connection to the database using a different set of MySql parameters than the database.php file. Again, it does NOT use database.php's MySql configuration.
Instead, cakephp defines new connection variables located at:
'app/webroot/discussion/config.php'
To solve the problem, simply change the
$dbhost => localhost -> $dbhost => yourservername
$dbname => wrongname -> $dbname => rightname
etc..
Keep in mind that it is possible the previous developer changed these values, so if this doesn't help you then good luck.
BTW, the error message above was the result of trying to connect to localhost.
To resolve this issue, I ran the following commands:
mysqld --tc-heuristic-recover=ROLLBACK
systemctl start mariadb.service