Deal with Swift-TransportException when sending Gmail from Laravel application

Error: ” Swift_TransportException Connection could not be established “

The problem has occurred when we send a mail from the production server using Gmail. The notice of exception is shown below.

Swift_TransportException Connection could not be established with host smtp.gmail.com [Permission denied #13]

Causes

This problem is caused by SELinux. So we will run some command for accepting httpd can open the socket and send mail to an outside destination.

Solution

To allow for HTTPD (i.e. PHP) to make Network Socket connections

setsebool -P httpd_can_network_connect on

To allow for HTTPD (i.e. PHP) to send out mail.

setsebool -P httpd_can_sendmail on

Leave a comment