-2

I am trying to send email using the gmail's smtp, but I am having erros. First, I had "class SMTP not found" following the github manual to install PHPMalier and I discovered that I needed to require the smtp class "class.smtp.php". I had errors yet, so I saw that I needed to require "PHPMailerAutoLoad.php" instead of "class.PHPMailer.php". Now, I am having others erros. I am tired! I am trying to fix that much time ago. Look the error that is happening:

Errors to send email using smtp.gmail.com

I made a class to send email like the example in the git:

<?php

    $txtName    = "Bruno";
    $txtAs    = "As";
    $txtEmail    = "Text mail";
    $txtMensage    = "Text Body";
    $mensageBody         = "<b>Name:</b> ".$txtName." <br><b>As:</b> ".$txtAs."<br><b>Message:</b> ".$txtMensage;

    require 'phpmailer/PHPMailerAutoload.php';
    require 'phpmailer/class.smtp.php';

    function smtpmailer($to, $from, $nameDes, $as, $body) {
        global $error;
        $mail = new PHPMailer();

        $mail->IsSMTP();
        $mail->SMTPDebug = 2;
        $mail->SMTPSecure = 'tls';
        $mail->Host = 'smtp.gmail.com';
        $mail->Port = 587;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = true;
        $mail->Username = 'mail@gmail.com';
        $mail->Password = 'pass';
        $mail->SetFrom($from, $nameDes);
        $mail->Subject = $as;
        $mail->Body = $body;
        $mail->AddAddress($to);
        $mail->IsHTML(true);

        if(!$mail->Send()) {
            $error = "<font color='red'><b>Mail error: </b></font>".$mail->ErrorInfo;
            return false;
        } else {
            $error = "<font color='blue'><b>Mensagem enviada com Sucesso!</b></font>";
            return true;
        }
    }

     if (smtpmailer('mail@gmail.com', 'mail@gmail.com', $txtName, $txtAs, $mensageBody)) {
         Header("location: sucesso.php");
     }
     if (!empty($error)) echo $error;

    ?>

My project tree is look this:

Project Tree

I already tried to find configs in the gmail account, and check these links: PHPMailer "Could not connect to SMTP host." phpmailer Could not connect to SMTP

And more... But nothing helped me. Please, I need help!

  • 1
    This is covered in the PHPMailer troubleshoting guide that the error message (and those other questions) links to. Read it. Also, you don't need to load the SMTP class manually if you've loaded the autoloader, and you don't need to load anything manually if you're using composer. – Synchro Sep 20 '16 at 12:51
  • Ok, I removed that, but the error persists. I already read the Troubleshooting, and I already tried a lot of things that I found there, but without solution yet. – Vinícius Biavatti Sep 20 '16 at 12:55
  • So what happened when you tried to telnet? – Synchro Sep 20 '16 at 12:58
  • Happened it: 220 smtp.gmail.com ESMTP h25sm15994499qtc.38 - gsmtp – Vinícius Biavatti Sep 20 '16 at 13:01
  • http://stackoverflow.com/questions/42471693/phpmailer-using-gmail-gives-error/42472146?noredirect=1#comment72085437_42472146 –  Feb 26 '17 at 18:46

1 Answers1

0

I found the error. I used the example of Locaweb for send emails using phpMailer, but I add SMTPSecure = 'tls'; and I got it!

This post helped me: "SMTP Error: Could not authenticate" in PHPMailer

This is the post about the phpMailer of Locaweb: (Portuguese) http://wiki.locaweb.com.br/pt-br/Enviar_e-mails_pelo_PHP_usando_o_PHPMailer

Thanks!!

Community
  • 1
  • 1