1

Here is my code below. But it keeps ending up in spam I already added authentication and changed the setfrom address but it still ends up in spam

        $mail->SMTPDebug = 3;                               

        $mail->isSMTP();                                     
        $mail->Host = 'localhost';

        $mail->SMTPAuth = true;
        // $mail->SMTPAutoTLS = true;
        $mail->Username   = '******';                     // SMTP username
        $mail->Password   = "******";         
        $mail->Port = 25;                             

        $mail->setFrom('info@canbeltech.com', 'Canbel Tech');
        $mail->addAddress($email);
        $mail->isHTML(true);

        $mail->Subject = 'Canbel Tech IMT Biometric Card Receipt';
        $mail->Body    = $body;

        if(!$mail->send()) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
            echo 'Message has been sent';
        }
        exit;
  • Here's a good general guide to debugging email problems in PHP: https://stackoverflow.com/a/24644450/5947043 – ADyson Feb 10 '20 at 10:37
  • 1
    One other thing though - it always ends up in spam of which provider(s), exactly? have you tried sending it to different addresses of different email providers? Are the results any different? In the code above you haven't even shown how you are setting the destination email address. – ADyson Feb 10 '20 at 10:39
  • @ADyson I am actually sending to a gmail provider. – stephen wonder Feb 10 '20 at 10:45
  • Ok. So have you tried sending to any others, as I mentioned? It might help you to narrow down your issue if you can see if the problem is specific to gmail, or not. In the meantime you should probably check the link I gave above, and see if there are any steps you need to take to make your mail more reliable. – ADyson Feb 10 '20 at 10:50
  • Have a read of [the docs on this subject](https://github.com/PHPMailer/PHPMailer/wiki/Improving-delivery-rates,-avoiding-spam-filters). It's unlikely you need auth when sending through localhost, and it probably won't make any difference to deliverability. – Synchro Feb 10 '20 at 10:59
  • because of DMARC relay it will go in spam https://dmarcian.com/smtp-relay-for-third-party-sender-dmarc-compliance/ need to send it will SMTP server that has proper DMARC relay value – Ronak Dhoot Feb 10 '20 at 11:06

0 Answers0