2

Estou tentando enviar um e-mail através da biblioteca PHPMailer, porem não obtive sucesso :/.

Servidor: HostGator

Segue código:

<?php 
$nome = $_POST["nome"];
$email = $_POST["email"];
$assunto = $_POST["assunto"];
$msg  = $_POST["msg"];

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require '../phpmailer/vendor/autoload.php';

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions

try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.hostgator.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '[email protected]';                 // SMTP username
    $mail->Password = 'minhaSenha';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 25;                                    // TCP port to connect to

    //Define o remetente
    $mail->setFrom($email, $nome);

    //Define o destinatário
    $mail->addAddress('[email protected]');     // Add a recipient

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = $assunto;
    $mail->Body    = '<html>De: '.$nome.'<br/>Email:'.$email.'<br/>Assunto:'.$assunto.'Mensagem: '.$msg.'</html>';
    $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.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}

Mensagem de erro:

2018-01-12 19:18:00 SERVER -> CLIENT: 220-br802.hostgator.com.br ESMTP Exim 4.89 #1 Fri, 12 Jan 2018 17:18:00 -0200 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.

2018-01-12 19:18:00 CLIENT -> SERVER: EHLO zulpix.com

2018-01-12 19:18:00 SERVER -> CLIENT: 250-br802.hostgator.com.br Hello zulpix.com [50.116.87.189]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP

2018-01-12 19:18:00 CLIENT -> SERVER: STARTTLS

2018-01-12 19:18:00 SERVER -> CLIENT: 220 TLS go ahead SMTP Error: Could not connect to SMTP host.

2018-01-12 19:18:00 CLIENT -> SERVER: QUIT

2018-01-12 19:18:00 SERVER -> CLIENT: 221 br802.hostgator.com.br closing connection SMTP Error: Could not connect to SMTP host. Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.

Consegui fazer funcionar no gmail, usando as configurações necessárias para ele E também tive que habilitar a opção no gmail "Permitir aplicativos menos seguros".

Porem não consigo mandar para o e-mail da hostgator.

Alguém poderia me ajudar?

OBS: We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.

Esse seria um bloqueio do servidor deles?

1 Resposta 1

3

Porta 25 não é uma porta segura, nem é usada em TLS:

$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25;                                    // TCP port to connect to

E conforme este link https://suporte.hostgator.com.br/hc/pt-br/articles/115000802394-Como-usar-o-e-mail-em-plataformas-externas-#dados

As portas corretas são:

  • IMAP SSL - 993
  • SMTP SSL - 465

Ou seja SMTP usa SSL e não TLS com a porta 465, correto:

$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
7
  • já tentei sem tls, com tls com porta 587, com porta 465 + ssl e sempre da o mesmo resultado 12/01/2018 às 20:51
  • @NicolasGuilhermeMatheus tem certeza que é o mesmo erro, não seria um erro diferente? O log que vc colocou é sobre a porta=25, cole o log conforme as porta e o protocolo correto.
    – Syzoth
    12/01/2018 às 20:52
  • ia editar a mensagem, com ssl, o erro é esse aqui: 2018-01-12 20:52:19 SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 12/01/2018 às 20:53
  • @NicolasGuilhermeMatheus primeiro troca o $mail->SMTPDebug = 2; por $mail->SMTPDebug = 3;, testa e pega o log e então edita a pergunta e cola o log lá na pergunta.
    – Syzoth
    12/01/2018 às 20:54
  • 2
    Guilherme Nascimento P cara, vocês são deuses, serio,ta funcionando agora, estou desde manhã tentando fazer isso funcionar(uma coisa tão simples), e por incrível que pareça, nada dava certo, é só eu entrar no stack que tudo muda, muito obrigado Guilherme de coração kkk. 12/01/2018 às 21:10

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .