I have a server with mail support, say example.com. I configured the server and added MX records via cpanel, so that I can receive and send mails via outlook.
example.com
outlook.
Finally I just solved the issue by replacing some of the settings as below and it worked :).
$mail->Host = "smtp-mail.outlook.com"; // SMTP server example $mail->Port = 587; $mail->SMTPSecure = 'tls';