CakePHP mail is not sent after upgrading server

I have a CakePHP application that is written with version 2.7.7.
Following is original environment setting on server before I upgrade with this source code.

PHP - 5.3.3
Apache - 2.2.15
CentOS - 6.10

With this original source code, the email is sent correctly and email config is as shown in below in app/Config/email.php.

public $smtp = array(
 'host' => 'startls://mail.xxx.com',
 'port' => 587,
 'username' => 'xxx@xxx',
 'password' => 'xxx',
 'transport' => 'Smtp',
);

Then, I had upgraded server with following versions and deploy the existing source code again.

PHP - 7.0.33
Apache - 2.4.47
CentOS - 7.x

After server upgraded, email is not working without error. So, I changed mail setting like following.

public $smtp = array(
    'host' => 'mail.xxx.com',
    'port' => 587,
    'username' => 'xxx@xxx',
    'password' => 'xxx',
    'transport' => 'Smtp',
    'tls' => true
);

Based on this setting, I created new crontroller and try to send mail.

<?php
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');

class MailTestController extends AppController
{

    public function index()
    {
        $this->autoRender = false;
        $receiver = 'xxx';
        App::uses('CakeEmail', 'Network/Email');
        $email = new CakeEmail();
        $email->config('smtp');
        $from_email_address = 'xxx@xxx';
        $email->from($from_email_address);
        $email->to($receiver);
        $email->subject('MAIL TESTING');
        $message = "mail sending test";
        if (!$email->send($message)) {
            CakeLog::write('debug', $this->Email->smtpError);
        }
    }
}

I have got following error when I try to send mail via cakephp.

Error: [SocketException] SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.

I’m not sure why is it happening like this. While I’m asking about this error to mail vendor, they said they already open port 587 in mail server for SMTP. So, I’m created new php code file called index.php to send mail with PHPMailer like following and try to send mail via that code in upgraded application server with command php index.php with the same host, username, password and port. Mail is sent and receive smoothly and no error occurrs. Error is only happened while I sent mail via cakephp application code. What do I need to check in my application server or mail server?

<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;
use PHPMailerPHPMailerException;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
    $mail->isSMTP();                                            //Send using SMTP
    $mail->Host       = 'mail.xxx.com';                     //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username   = 'xxx@xxx';                     //SMTP username
    $mail->Password   = 'xxx';                               //SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;            //Enable implicit TLS encryption
    $mail->Port       = 587;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

    //Recipients
    $mail->setFrom('xxx@xxx', 'Mailer');
    $mail->addAddress('xxx', 'John Doe');     //Add a recipient
    
    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật