Error sending email in gmail with Phpmailer

Asked

Viewed 293 times

0

I used this code for a long time and it worked very well until now it simply doesn’t work anymore, neither with outlook nor with gmail.

<?php if($_SERVER['REQUEST_METHOD'] == 'POST' and !empty($_POST['contact_send'])) {
    $contact_name = !empty($_POST['contact_name']) ? true : false;
    $contact_telefone = !empty($_POST['contact_telefone']) ? true : false;
    $contact_email = !empty($_POST['contact_email']) ? true : false;
    $contact_mensagem = !empty($_POST['contact_mensagem']) ? true : false;
    if(!empty($contact_name) and !empty($contact_telefone) and !empty($contact_email) and !empty($contact_mensagem)) {

        date_default_timezone_set('America/Sao_Paulo');
        $datenow = date('d/m/Y', time());
        $timenow = date('H:i', time());

        $from = $_POST['contact_email'];
        $from_name = $_POST['contact_name'];
        $subject = $_POST['contact_name'];
        $msg = '<p>Telefone: ' . $_POST['contact_telefone'] . '</p>
                <p>Email: ' . $_POST['contact_email'] . '</p>
                <p>Data e hora: ' . $datenow . ' | ' . $timenow . '</p>
                <p>Mensagem: ' . $_POST['contact_mensagem'] . '</p>';

        $account = "[email protected]";
        $password = "123";
        $to = "[email protected]";

        require_once("plugins/mail/PHPMailerAutoload.php");

        $mail = new PHPMailer();
        $mail -> IsSMTP();
        $mail -> CharSet = 'UTF-8';
        $mail -> Host = "smtp.gmail.com";
        $mail -> SMTPAuth = true;
        $mail -> Port = 587;
        $mail -> Username = $account;
        $mail -> Password = $password;
        $mail -> SMTPSecure = 'TLS';
        $mail -> From = $from;
        $mail -> FromName = $from_name;
        $mail -> isHTML(true);
        $mail -> Subject = $subject;
        $mail -> Body = $msg;
        $mail -> addAddress($to);

        if(!$mail -> send()) {
            echo $mail -> ErrorInfo; } } } ?>

The message that shows is of smtp error with both gmail and outlook, any of the two of smtp error, but the senha and the usuário are correct.

Someone could help me with both the problem regarding gmail and outlook and or the use of another smtp server for example zohomail or email.com.

I do not make a point of using gmail or outlook just did not want to modify this code too much because I do not know if you agree, but it is quite functional. In case I think it is problem in gmail and outlook that no longer allow as it worked and simply stopped.

  • Related https://answall.com/questions/89690/envio-de-email-via-phpmailer-para-gmail?rq=1

  • Try using Port = 465 with Smtpsecure = 'SSL';

  • @Leocaracciolo boy, already tried 465 995 ssl and tls all give the same error

  • Gmail back and forth is a problem, I’ve seen many problems with gmail here. Why don’t you use email.com? I use it and it’s never been a problem

  • But what is the description of the error? Put $mail->SMTPDebug = 2; and check in the log that you generate what is happening. Post what occurred.

  • I posted your code on my server, and it worked. My email server is not Gmail. It’s from my hosting service

  • as I explained, the error is SMTP connect() failed

  • in case you used exactly my code putting only the smtp of your server and the user and password of your server? which your server? in case my of gmail and outlook error did not try with another server

  • exactly that, smtp.meudominio.com, I have several domains

  • yes, I do too, but which smtp did you use?

  • @Leocaracciolo you downloaded phpmailer on github?

  • Yes, but only those 3 Phpmailerautoload.php class.smtp.php and class.phpmailer.php

  • host. configuration look: https://support.google.com/a/answer/176600?hl=pt-BR

  • try sending from a server, it may be your environment too that is zoado.

  • @Leandro could be the Hostinger drug, so do you know any test hosts? that work?

Show 10 more comments
No answers

Browser other questions tagged

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