I am using Mail Queue to send emails in my application (https://pear.php.net/package/Mail_Queue/)
The same code works fine on windows (php version: 5.5.28) and it gives the below mentioned exception on unix (php version 5.6)
PHP User Notice 'yii\base\ErrorException' with message 'Error in sending mail: authentication failure [SMTP: STARTTLS failed (code: 220, response: Begin TLS negotiation now)]'
The mail server credentials are fine. They are same on linux as well as on windows. Code 220
means the server is ready
(via http://www.serversmtp.com/en/smtp-error)
I read somewhere it is due to php5.6 and it will work fine on 5.5 but I don't think so that would be a valid answer/solution to the problem.
I guess this is because PHP 5.6 does SSL peer verification by default and PHP 5.5 doesn't. I guess if you fix a valid SSL certificate it should work, or disable ssl verify-peer in your code.
Without knowledge of Mail_Queue I don't know how to fix it without any example code.
Sending emails from EC2 instances is limited by Amazon and strictly throttled at network level. This is to prevent spamming and other abuses.
If you have a large amount of emails to send to your customers, the recommended way is to use Amazon Simple Email Service. With Amazon SES, you can send transactional email, marketing messages, or any other type of high-quality content and you only pay for what you use.
Connecting to the Amazon SES SMTP Endpoint
If you really need to send emails from an EC2 instance, you must use an Elastic IP Adress and ask Amazon's support to remove limitations on SMTP traffic from that EIP.
Alternatively I will suggest you can use Sendgrid, they are fast and accurate, provides 12000 emails per month for free as well.