E-mail sent by phpmailer function goes to spam

Asked

Viewed 443 times

0

The code below sends the email properly, however, it goes to the spam box, be it for Gmail, Yahoo, Outlook etc. Is the problem in the code or the server that sends the email?! Just to indicate the server I use is at http and not https.

<?php
//Chama a classe
require("phpmailer/class.phpmailer.php");

if(isset($_POST['send'])){

    //Variáveis enviadas pelo formulário
    $nome = $_POST["name"];
    $emailUsuario = $_POST["email"];
    $assunto = $_POST["subject"];
    $sugestao = $_POST["message"];

    //Instanciando o objeto
    $mail = new PHPMailer();

    //Define os dados do servidor e tipo de conexão
    $mail->IsSMTP(); // Define que a mensagem será SMTP
    $mail->Host = "mail.meudominio.com"; // Endereço do servidor SMTP
    $mail->SMTPAuth = true; // Autenticação
    $mail->Port = 25;
    $mail->Username = '[email protected]'; // Usuário do servidor SMTP
    $mail->Password = 'senha'; // Senha da caixa postal utilizada

    //Define o remetente
    $mail->From = "[email protected]"; 
    $mail->FromName = "Nome Empresa";

    //Define os destinatário(s)
    $mail->AddAddress('[email protected]', 'Nome');
    $mail->AddAddress('[email protected]');
    $mail->AddCC('[email protected]', 'Nome Nome'); // cópia normal
    $mail->AddBCC('[email protected]', 'Nome Nome');// cópia oculta

    //Define os dados técnicos da Mensagem
    $mail->IsHTML(true); // Define que o e-mail será enviado como HTML
    $mail->CharSet = 'UTF-8'; // Charset da mensagem (opcional)

    //Texto e Assunto em formato HTML
    $mail->Subject  = $assunto; // Assunto da mensagem
    $mail->Body = '<html>
        <head>
        </head>
        <body style="background-color:#d0e2f4;color:#808080;" align="center">
            <div style="width:70%;background-color:white;padding:20px;" align="left">
                <p><font face="arial">Nome: ' . $nome . '</font></p>
                <p><font face="arial">Email: ' . $emailUsuario . '</font></p>
                <p><font face="arial">Assunto: ' . $assunto . '</font></p>
                <hr style="color:#f2f2f2;">
                <br>
                <p style="color:#808080;font-size:14px;"><font face="arial">' . $sugestao . '</font></p>
                <br>
            </div>
            <div style="font-size:12px;" align="center">
                <p><font face="arial">Nome Empresa</font></p>
                <p><font face="arial">Slogan Empresa</font></p>
                <p><font face="arial">www.siteempresa.com</font></p>
                <br>
                <br>
            </div>                                                          
        </body>
    </html> ';

    //Aqui faz o envio da mensagem
    $enviado = $mail->Send();

    //Limpa os destinatários e os anexos
    $mail->ClearAllRecipients();
    $mail->ClearAttachments();
}

?>

  • In addition to the links mentioned above, a good way to know why you’ve fallen into spam is to open the email and view its RAW file (see the original email, with headers and everything in between)

  • Thank you for the indication. I will rearrange the code.

  • 1

    Before the code, look at the original email that got spam. The explanation is probably there, and it’s not related to the code, but to a problem on the DNS or the server (which is your initial question, and has explanations for the various answers linked above)

  • 1

    Right now my spam box is clean, but if anything comes up soon, I’ll send you an example print of where to look.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.