My solution to send mail with gmail in prod server

Hi,

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 smtp.gmail.com [ #0]

This is my code :

// Email parameters
$mail_smtp_server    = 'smtp.gmail.com';        // SMTP server name or IP address
$mail_smtp_user      = 'BLABLA@gmail.com';                   // SMTP user name
$mail_smtp_pass      = 'PASSWORD';                // SMTP password
$mail_from           = 'BLABLA2@gmail.com';          // From email
$mail_to             = 'BLABLA3@gmail.com';         // 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";
sc_mail_send($mail_smtp_server,
			 $mail_smtp_user,
             $mail_smtp_pass,
			 $mail_from,
			 $mail_to,
			 $mail_subject,
			 $mail_message,
			 $mail_format,
			 $mail_copies,
			 $mail_tp_copies,
			 $mail_port,
			 $mail_tp_connection);

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 https://support.google.com/mail/?p=BadCredentials

Solution : Click here https://myaccount.google.com/lesssecureapps?pli=1 and enable Allow less secure apps: ON

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

Thank

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.