Swiftmailer connection exception - smtp connection failed (ssl) - php

ive been looking online for hours for solution in this problem of mine.
I just simply would like to send emails using gmail smtp, php, and swiftmailer
I am using kohana for this. Xampp 1.7.4. At first, it displays an error about ssl not being configured in php. I googled and added a new line in php.ini, that is (extension = php_openssl.dll), and pasted two dll files from php folder to apache bin folder (libeay32.dll and ssleay32.dll). but to no avail, it still wont allow me to send emails..
Here's the error being displayed, i cant find similar problems online... anyone pls. help.
Swift_ConnectionException
C:/xampp/htdocs/gbs/system/vendor/swift/Swift/Connection/SMTP.php [309]:
The SMTP connection failed to start [ssl://smtp.gmail.com:465]: fsockopen returned Error Number 0 and Error String ''
Stack Trace
* system\vendor\swift\Swift.php [216]:
Swift_Connection_SMTP->start( )
* system\vendor\swift\Swift.php [101]:
Swift->connect( )
* system\helpers\email.php [103]:

This is just a wild guess based on a similar problem I had, so I could be that it has nothing to do with it.
What I'm thinking is that somewhere you have to give the path to the root certificat authority file.
On my computer it is located in /etc/ssl/certs/ca-certificates.crt, but you will have to find out where it is on your computer/server. Now the problem is finding out how you can pass that on through swiftmailer.
Another thing the make sure is in the swiftmailer documentation:
For SSL or TLS encryption to work your PHP installation must have appropriate OpenSSL transports wrappers. You can check if "tls" and/or "ssl" are present in your PHP installation by using the PHP function stream_get_transports()

Related

laravel shows error when sending email using tls and my own postfix/virtualmin server [duplicate]

This question already has answers here:
Laravel certificate verification errors when sending TLS email
(2 answers)
Closed 1 year ago.
We have installed our own postfix/virtualmin server and we have a laravel application,the problem is when we use external smtp servers, it is not problem to use tls option, and the emails are getting sent ok, but when using our new smtp server, when using tls we have 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
It has to be something regarding missing certificates in our postfix/virtualmin server, but, i do not know where to start, we have already a letsencrypt certificates for it, but i believe we maybe need to convert them to ca or something like that ? i'm not sure, that's why i need your help.
Thank you,
Download the latest cacert.pem file from cURL website.
wget https://curl.haxx.se/ca/cacert.pem
Edit php.ini (you can do php --ini to find it), update (or create if they don't exist already) those two lines:
curl.cainfo="/path/to/downloaded/cacert.pem"
...
openssl.cafile="/path/to/downloaded/cacert.pem"
Those lines should already exist but commented out, so uncomment them and edit both values with the path to the downloaded cacert.pem
Restart PHP and Nginx/Apache.
I figured it out the problem.
My virtualmin/postfix setup was missing the CA certificiation, and since i used letsencrypt for ssl, i had to put the path of generated CA in the config.
Here : Webmin --> Servers ---> PostFix Mail Server ----> Smtp authentication and encryption.

PHP mailer works in localhost but shows the following error in server

I tried all the solutions given to questions similar to mine (allowed less secured apps, display captcha, using 465 port for ssl, etc).
Can anyone tell if I have to change any settings on cpanel to send mails using gmail?
I remove below line from localhost code and it worked.
define("MAILER", "smtp");
Above line is not required and causing the error

PHP Imap Certificate failure

I was pulling my inboxes using php-imap/php-imap library and inboxes managed by CPanel. All in sudden script stopped with following error.
Connection error: Certificate failure for imap.domain.com:
Server name does not match certificate:
/OU=Domain Control Validated/OU=PositiveSSL/CN=<amazon.domain.com>
in /.../vendor/php-imap/php-imap/src/PhpImap/Mailbox.php
here is the imap path I am using:
{imap.domain.com:143/imap/tls}INBOX
I also tried {imap.domain.com:143/novalidate-cert/imap/tls}INBOX but all in vain.
What change could have have stopped it?
How to fix it and avoid such failure in future?
IMAP port is 993..143 for POP..Try it..
{imap.domain.com:993/imap/ssl/novalidate-cert}INBOX

Drupal - PHP SMTP Settings are correct but email will not send

I get the following error when my Drupal site tries to send out a welcome email when users are signed up: Failed to connect to mailserver at "secure.emailsrvr.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
I at first set the following in PHP.ini:
SMTP = secure.emailsrvr.com
SMTP_PORT = 465
sendmail_from = support#managerspitstop.com
username = support#managerspitstop.com
password = ****
But I still got the error above so I added the following into the mail.inc file which is a file within the Drupal site:
ini_set("SMTP","secure.emailsrvr.com");
ini_set("smtp_port","465");
ini_set("username", "support#managerspitstop.com");
ini_set("password", "*****");
ini_set("sendmail_from", "support#managerspitstop.com");
But still get the same error. So I contacted Rackspace who I have set up the email with and they have told me the settings I am using are correct. To test this I added the email to Outlook 2013 send out and email and received an email just fine.
I have looked around and couldn't find a solution. Any help will be greatly appreciated.
Please note that this is just a hint for better investigation means, not an answer.
It would be beneficial to make a packet-level inspection of what exactly is going on at the time, when you try to send e-mail out.
For this, install tcpdump:
apt-get install tcpdump
and start a packet capture (run as root):
tcpdump -i any -s 0 -w /tmp/sniff-465.pcap port 465
Perform steps necessary to attempt the e-mail submission to the SMTP server, wait for the response and stop the packet capture by pressing CTRL+C. The resulting file (/tmp/sniff-465.pcap) can be analysed (using wireshark, i.e.) for exact behavior of the attempted SMTP transaction.
BLOODY DRUPAL! Managed to get it working. Turns out my email settings were correct the whole time.
I fixed it by downloading Drupals SMTP module which I placed in httpdocs/sites/all/modules/smtp and then I downloaded phpmailer version 2.2.1 (only required if you are running Drupal 6.x and do not use a version of PHPMailer any higher than 2.2.1 as it will not work) https://github.com/PHPMailer/PHPMailer/releases/tag/v2.2.1 I placed this at httpdocs/sites/all/modules/smtp/phpmailer.
Once that was sorted I went into the Administration section of my Drupal site and went to the modules section and typed in the email settings and BAM it worked :D.

APNS + PHP "stream_socket_client(): Failed to enable crypto"

I'm having trouble with using APNS with PHP and getting the following message:
stream_socket_client(): Failed to enable crypto
The problem only happens sometimes, and other times it would actually send the push.
Since I have the test script on a loop of 10 iterations, I would sometimes get this:
stream_socket_client(): SSL: Connection reset by peer
I'm testing using the sandbox server tls://gateway.sandbox.push.apple.com:2195
Here is what I tried:
I tried to reissue the PEM and all certificates with it.
I played around with the request protocol sslv3:// and tls://.
I played around with the passphrase (push worked without the passphrase btw)
I tried searching stackoverflow for a solution and nothing worked.
Checked pem file permissions 644
Checked pem parent directories permissions 755
It seems that all the solutions I found on Google and SO are people having problem pushing altogether.
I feel like the service is rate limited maybe? Because we waited a while (around 15 minutes) and then tried it again, and was able to successfully push around 100 messages until I started getting that message again.
The sandbox push service is rate limited. I have experienced this myself when testing but have never encountered any such limit using the production API.
You might also be hitting their other protections.
Are you opening a connection, sending a message, closing connection and then looping and doing it all over again?
That will get your notifications dropped. Apple wants you to send several push notifications using the same connection, not a new one each time.
Best Practices for Managing Connections
You may establish multiple connections to the same gateway or to
multiple gateway instances. If you need to send a large number of
remote notifications, spread them out over connections to several
different gateways. This improves performance compared to using a
single connection: it lets you send the remote notifications faster,
and it lets APNs deliver them faster.
Keep your connections with APNs open across multiple notifications;
don’t repeatedly open and close connections. APNs treats rapid
connection and disconnection as a denial-of-service attack. You should
leave a connection open unless you know it will be idle for an
extended period of time—for example, if you only send notifications to
your users once a day it is ok to use a new connection each day.
From Apple Docs # https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html
My PHP code was generating following error:
PHP Warning: stream_socket_client(): Failed to enable crypto in /private/tmp/t.php on line 12
PHP Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /private/tmp/t.php on line 12
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /private/tmp/t.php on line 24
The problem was, the damn certificate, expired the day before yesterday! :-) Can you believe this?
So, I need to recreate my PEM file.
It is not necessary recreate your pem file
that error happens when you use an incorrect PassPhrase
regards
Emiliano
I had this problem. Disappeared after giving write permission for 'everyone' for the .pem file.
I have this problem because I foolishly forgot to include the file extension (.pem) when supplying the file path for local_cert.
few checks :
device token should be - with out spaces and with out < or >
make sure the path of certificate is correct and expired date of it.
make sure the passphrase you are using is the one u used to make certificate
In my case, the issue was with my mac (OSX Sierra). I uploaded php and cert to my server, ran it, and the notification was delivered.
I tried examples from book of Marin Todorov iOs 6 by Tutorials.
And before I could send push notifications for automatical update I had a lot of headache cause of handshake error - stream_socket_client(): Failed to enable crypto.
I did all of what I found in Stackoverflow - changed permissions on certificate and others.
What I did eventually?
I created selfsigned SSL certificate and setup Apache for serving SSL.
Also I changed SSL protocol from ssl to tls in hostname:
tls://gateway.push.apple.com:2195
After that service works.

Categories