My solution to send mail with gmail in prod server


Many of you have problems sending emails with gmail.

First, try it out on your production environment. On Windows with the Scriptcase environment, I have not yet managed to get it working, this is my error :

Fatal error: Uncaught Swift_TransportException: Connection could not be established with host [ #0]

This is my code :

// Email parameters
$mail_smtp_server    = '';        // SMTP server name or IP address
$mail_smtp_user      = '';                   // SMTP user name
$mail_smtp_pass      = 'PASSWORD';                // SMTP password
$mail_from           = '';          // From email
$mail_to             = '';         // To email
$mail_subject        = 'Test message';            // Message subject
$mail_message        = 'This is a test message.'; // Message body
$mail_format         = 'T';                       // Message format: (T)ext or (H)tml
$mail_copies         = '';                        // List of the emails that will recieve the message
$mail_tp_copies      = '';                        // Type copies: BCC (Hiden copies) or CCC (Regular copies)
$mail_port           = '465';                     // Server port
$mail_tp_connection  = 'S';                       // Connection security (S) or (N)

// Send email";

In my production serveur in /var/log/apache/error.log i can see :

PHP Fatal error: Uncaught Swift_TransportException: Expected response code 250 but got code “535”, with message "535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8

Solution : Click here and enable Allow less secure apps: ON

So now in Windows in the development environment what should I do?


I see that your are using Gmail for the email. I had the same problem and had to enable less secure apps in the Gmail Account. Have a look at this link How to enable less secure apps to access gmail accounts or you can google for Gmail Less secure apps.