0

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   = 'name@mydomain.com';                     
        $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('name@mydomain.com');
        $mail->addAddress('joeuser@gmail.com', 'Joe User');  
        $mail->addAddress('joeuser@hotmail.com', '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.

ubkra
  • 1
  • 2
  • Read the section about the spam and [this related topic](https://stackoverflow.com/questions/371/how-do-you-make-sure-email-you-send-programmatically-is-not-automatically-marked) – DarkBee May 06 '22 at 06:20
  • Did you check the rule of your Microsoft Outlook email? maybe your email was tagged as spam or junk email – Ainz May 06 '22 at 06:22
  • I've used this tool; https://dkimvalidator.com/ DKIM, validating signature is pass. SPF result Pass. Other point to note SpamAssassin Score: -5.111, Message is NOT marked as spam – ubkra May 06 '22 at 09:13
  • I've also used this tool and get 10/10 score https://www.mail-tester.com/ – ubkra May 06 '22 at 09:20
  • You could [read PHPMailer's docs on this subject](https://github.com/PHPMailer/PHPMailer/wiki/Improving-delivery-rates,-avoiding-spam-filters) too. – Synchro May 06 '22 at 09:29
  • I've gone over the above comments again, spoken with Hostgator support. Still ALL emails go to Junk. – ubkra May 07 '22 at 00:15

0 Answers0