'How can I ensure ensure emails from my domain get delivered and avoid them being marked as spam by Hotmail/Outlook? [duplicate]
I'm using PHPMailer to send emails from my hostgator webserver account. It's working as I'm getting emails at my professional domain and gmail fine. But when the recipient is with outlook, hotmail etc it ALWAYS goes to the spam folder.
I've got two subdomains with hostgator, I've tried with both and it's the same.
The email I'm sending from is a valid email address.
To clarify, I'm not using the PHP mail function, I'm using PHPMailer and the emails are being sent. It's just going to the junk folder ALWAYS.
Here is my code
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'mail.mydomain.com';
$mail->SMTPSecure = "ssl";
$mail->Username = '[email protected]';
$mail->Password = 'mypassword';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->setFrom('[email protected]');
$mail->addAddress('[email protected]', 'Joe User');
$mail->addAddress('[email protected]', 'Joe User');
$mail->isHTML(true);
$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}";
}
I've tried to post the headers but the system will not allow.
Google suggests this has been a widespread problem but nothing recent so looking for a solution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|