While working on Faveo Helpdesk Community version on my new system, I got stuck while setting up system email. At first, it was strange as the code has not been updated since the last release and I was able to set up the email in my old system which had Windows and Linux OS. After trying a few times and getting the same error as shown below
Connection could not be established with host smtp.gmail.com
I decided to inspect the code. But before that, I tested the functionality on local Windows/Linux servers along with the remote test server and it worked on all servers except my new system which has MacOS (Unix system). Now it was time to dig up the code. I found the Swiftmailer was using stream_socket_client() which was causing the issue. More details about the method can be found here. After finding the culprit it was time to face it, so I ran PHP shell and pasted the method with all expected inputs. It returned this in my terminal screen
OpenSSL error!!! would not it be great if Swiftmailer was throwing the same error instead of echoing the entirely different error giving no clue about the issue. Anyway, I continued to search the error and ended up landing on this StackOverflow question. This was getting the same error in the same environment.
Here’s how he solved it
- Open the command line and run:
I did the same and got the warning as my system is new and I had not setup the locate database. I ran the comand which appeared in the warning to startup locate database after which it took some time to setup and generate the data.
Once locate.database was setup I ran the above command again and got the locations for cacert.pem
- I downloaded the most recent one from curl and updated my cacert.pem with it.
- I opened up my php.ini file and placed this line at the top of the file:
- Restart apache (stop apache and start it again)
Once I completed all these steps I ran stream_socket_client() in PHP shell and this time it worked without any issue.
As it solved the issue with initiating a stream or datagram connection to the remote host, I was finally able to set up the email in my Faveo community system.
Next time if you face the same issue, you might want to check stream_socket_client() before scratching your head.