Email Sending Issue on nginx Server

I have shifted my website to a new Nginx server with PHP 7.4, Apache 2.4, and OpenSSL 1.1.1n. If I try to send an email from default PHP settings it sends the email successfully but it will go to spam/junk which is fine with me. We use ZohoMail and Office365 on different cpanel accounts.

$mail->Encoding = "base64";
$mail->SMTPAuth = true;
$mail->Host = "smtppro.zoho.com";
$mail->Port = 465;
$mail->Username = '[email protected]';
$mail->Password = 'yourpassword';
$mail->SMTPSecure = 'SSL';
$mail->isSMTP();
$mail->IsHTML(true);
$mail->CharSet = "UTF-8";
$mail->From = "[email protected]";
$mail->FromName = 'Company';
$mail->addAddress('[email protected]');
$mail->Body="Test email sent successfully.";
$mail->Subject="Test Email";
$mail->SMTPDebug = 1;
$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str"; echo "<br>";};
if(!$mail->Send()) {
    echo "Mail sending failed";
} else {
    echo "Successfully sent";
}

The server is not accepting any SMTP settings but the default PHP email works. Please guide me to solve this issue as I’m new to nginx servers.