i am trying to send email with attachment in PHP using SMTP and PEAR but getting the error as \"authentication failure [SMTP: STARTTLS failed (code: 220, response: 2.0.0 Rea
The undocumented parameter: socket_options , let me authenticate when I got this error:
authentication failure [SMTP: STARTTLS failed (code: 220, response: TLS go ahead)].
I just need add :
'auth' => "PLAIN",
'socket_options' => array('ssl' => array('verify_peer_name' => false)),
Taken from: https://pear.php.net/manual/en/package.mail.mail.factory.php
I was getting this error, but even disabling STARTTLS (as several of the above comments suggest) didn't help, as it then reported an authentication error. I found the proper fix for at least my situation.
If you're using PHP 5.6, there are changes to SSL: http://php.net/manual/en/migration56.openssl.php
Mainly, there is extra verification done on the connection. This verification wasn't done on 5.5 so these issues were ignored. But in my situation, the server was sending the SMTP EHLO command with "localhost" and apparently that causes PHP's new verification to fail.
The solution is to patch osTicket's mail class at /include/pear/Net/SMTP.php - change this line:
$this->_socket_options =$socket_options;
to
$this->_socket_options = array('ssl' => array('verify_peer_name' => false));
This turns the verification off. For my setup, the mail server is on the same local network as the osTicket server, so I'm not overly concerned about the security.
The other solution is to downgrade to PHP 5.5 which doesn't have this extra verification.
It'd be nice if osTicket somehow offered a setting for this so patching the code isn't necessary every time.
Taken from: https://github.com/pear/Net_SMTP/issues/14