Phpmailer_5.2.4 with GMAIL

Asked

Viewed 100 times

0

I’ve seen several topics and sites talking about phpmailer sending direct to GMAIL, however I can’t do, the following error appears:

SMTP -> ERROR: Failed to connect to server: Connection timed out (110) 
The following From address failed: ***@gmail.com : Called Mail() without being connected

CODE:

<?php
    session_start();
    ob_start();

    $nome = $_POST['nome'];
    $email = $_POST['email'];
    $telefone = $_POST['tel'];
    $mensagem = $_POST['mensagem'];

    if($_POST['nome'] != '' && $_POST['mensagem'] != ''){
        require("phpmailer/class.phpmailer.php");
        // Inicia a classe PHPMailer

        $mail = new PHPMailer();

        // Define os dados do servidor e tipo de conexão

        // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

        $mail->Host = 'smtp.gmail.com';

        $mail->Port = 587;

        $mail->SMTPAuth = true;

        $mail->SMTPDebug = 1;

        $mail->SMTPSecure = 'tls';

        $mail->IsSMTP(); // Define que a mensagem será SMTP

        $mail->SMTPAuth = true; // Usa autenticação SMTP? (opcional)

        $mail->Username = '***@gmail.com';
        $mail->Password = '***';

        // Define o remetente

        // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

        $mail->From = "***@gmail.com"; // Seu e-mail
        $mail->FromName = "Contato Show de Quimica"; // Seu nome

        // Define os destinatário(s)

        // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        $mail->AddAddress('***@gmail.com');
        $mail->AddReplyTo($email);

        // 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

         // Define a mensagem (Texto e Assunto)
        // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        $mail->Subject  = "Mensagem de Contato Show de Quimica"; // Assunto da mensagem
        $mail->Body = "<font style=\"font-size:16px\"><b>Nome:</b> $nome; <br /><b>E-mail:</b> $email; <br /><b>Telefone:</b>$telefone; <br /><br /><b>Mensagem:</b><br />$mensagem</font>";
        $mail->AltBody = "Nome: $nome;\r\n E-mail: $email;\r\n\r\n Mensagem:\r\n $mensagem;\r\n\r\n Telefone:\r\n $telefone";
        // Envia o e-mail

        $enviado = $mail->Send();

        // Limpa os destinatários e os anexos
        $mail->ClearAllRecipients();
        $mail->ClearAttachments();
    }
?>
  • Take a look at if it’s the same problem: http://forum.imasters.com.br/topic/473485-resolvidophpmailer-e-gmail/ when I was emailing gmail I had to use port 468 with ssl and had to allow less secure apps in my gmail account.

  • I’ve used this port with SSL

  • Ready to allow it, but continue the same way :(

  • 1

    I suggest running only the Phpmailer sample file using gmail. With this example you will be able to see more information about the error that is happening. From there you can consult the section of problems, on the Phpmailer wiki.

  • I followed this link and it worked: https://support.google.com/mail/answer/78754

No answers

Browser other questions tagged

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