PHP Mail is going to Gmail but not Office 365 accounts

I'm sending a HTML email and it is arriving at gmail accounts but not at Office 365 Accounts. My code is below please help me troubleshoot.

if (isset($_POST['submit-forgot'])) {
    $flag = true;
    if (isset($_POST['email-forgot'])) {
        $email = $_POST['email-forgot'];
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $alert = '<div class="alert alert-danger">You must enter a valid email address</div>';
            $flag = false;
        } else {
            $sql = "SELECT * FROM users WHERE email = '$email'";
            $result = $db->query($sql);
            $array = $result->fetch_assoc();
            if ($result->num_rows == 1) {
                $hex = bin2hex(random_bytes(16));
                $sql = "UPDATE users SET hex = '$hex' WHERE email = '$email'";
                $result = $db->query($sql);
                $to = $array['email'];
                $subject = 'Password Reset';
                include 'includes/mail.php';
                $headers  = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                $headers .= 'From: do-not-reply@effinghamministorage.com' . "\r\n";
                $headers .= "To: $to\r\n";
                mail($to, $subject, $message, $headers);
                $alert = '<div class="alert alert-success">If the email address you entered is on file you will receive an email.</div>';

            }
        }
    }
}

Open in new window


<?php
$message = '
<html>
<head>
    <title>Reset Your Password</title>
</head>
<body>
<h1>Thanks for being a customer.</h1>
<h2>This link can only be used one time for security purposes.</h2>
<table cellspacing="0" style="border: 2px dashed #FB4314; width: 300px; height: 200px;">
    <tr>
        <th>Name:</th><td>CodexWorld</td>
    </tr>
    <tr style="background-color: #e0e0e0;">
        <th>Email:</th><td>contact@codexworld.com</td>
    </tr>
    <tr>
        <th>Reset Link:</th><td><a href="http://accounts.effinghamministorage.com/resetpassword.php?hex=' . $hex . '">Reset Password</a></td>
    </tr>
</table>
</body>
</html>';

Open in new window

burnedfacelessAsked:
Who is Participating?
 
gr8gonzoConsultantCommented:
This is such a frequent problem that I wrote an article on how to solve it.
https://www.experts-exchange.com/articles/1222/16-Tips-to-Improve-Email-Delivery.html
2
 
Ares KurkluSoftware EngineerCommented:
I suggest you try to email to a few other domains as well, it may have to do just with office 365, they may be ending up as spam.
0
 
Dave BaldwinFixer of ProblemsCommented:
Good article but the current site for PHPMailer is https://github.com/PHPMailer/PHPMailer .
0
 
burnedfacelessAuthor Commented:
Thanks guys I'm going to install PHP Mailer and give that a try.
0
 
gr8gonzoConsultantCommented:
Tips #5 and #6 are the most critical ones from that article. Make sure you implement BOTH. They both have HUGE impacts in avoiding spam filters.

Thanks for the note about the new url, Dave. The article is about 8 years old so it definitely needs an update!
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.