php – Outlook Email Inbox/Junk Not Receiving Sent Mail from Personal Website Using PHPMailer/SMTP


I have created a PHPMailer Script that sends an email through SMTP to a location that I specify. The location that I would like to use is the domain email that I obtained through Microsoft Outlook. My website is through shared Hosting by HostGator, and the script seems to work well when sending to my Gmail account. However when sending emails to my Outlook address, they do not appear in either my inbox/junk despite my try/catch producing a “message has been sent,” echo.

I have specified to my Outlook email that both the Host and the Domain that the email is being sent from are safe senders, yet it does not make a difference. Any suggestions/help with the code or email is greatly appreciated. Thank you in advance. Here is my script:

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

require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';

$mail = new PHPMailer(true);         
if (isset($_POST('submit'))){            
        $name = $_POST('name');
        $email = 'example@gmail.com';
        $subject = $_POST('subject');
        $message = $_POST('message');
        $mailTo = 'example@outlook.com';
    try {
        //Server settings
        $mail->SMTPDebug = 2;               
        $mail->isSMTP();                               
        $mail->Host = 'example';                  
        $mail->SMTPAuth = true;                               
        $mail->Username = 'example@outlook.com';            
        $mail->Password = 'examplePassword';                       
        $mail->SMTPSecure = 'ssl';                           
        $mail->Port = 465;                                

        //Recipients
        $mail->setFrom($email);         
        $mail->addAddress($mailTo); 

        //Content
        $mail->isHTML(true);                                 
        $mail->Subject = $subject;
        $mail->Body = '<h1>Email Sent from - Website</h1>'."nn".'<p>From: '.$name.'</p>'.'<p>'.$message.'</p>';
        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    }
}
?>