Wamp Server how to send an email using a gmail account using a php on localhost?

0

Personal I'm having a problem sending an email with user registration validation code from my localhost. In my localhost I have the Wamp Server installed configured to use port 80, I redirected all external accesses to the IP of my host to port 80 in this way it is possible to access the server externally for access to the database etc ... I did several searches on the internet how to do this I found tutorials using Sendmail that did not give anything or if an error just said that the email was sent, but when checking in the email inbox nothing. I found PHPMailer that at least presented an error that was:

SERVER - > CLIENT: SMTP NOTICE: EOF caught while checking if connected SMTP Error: Authentication failed. SMTP Connect () failed. link Error: SMTP Connect () failed. link

NOTE: I did everything the tutorials said I even tried to use an example for gmail that comes with the class when you download Github. Could someone give me a solution or alternative that is not paid? Below my php code:

<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->setLanguage('pt');
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';

$host = 'smtp.gmail.com';
$username = '[email protected]';
$password = 'minha_senha';
$port = 465;
$secure = 'ssl';

$from = $username;
$fromName = 'Meu Nome Completo';

$mail->IsSMTP();
$mail->Host = $host;
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;
$mail->Port = $port;
$mail->SMTPSecure = $secure;

$mail->From = $from;
$mail->FromName = $fromName;
$mail->addReplyTo($from, $fromName);

$mail->addAddress('destinatario@qualquer_dominio.com', 'Nome do Destinatario');

$mail->isHTML(true);
$mail->CharSet = 'utf-8';
$mail->WordWrap = 50;

$mail->Subjet = 'Testando phpmail';
$mail->Body = 'Enviando emails com <b>PHPMailer</b> para <h2>TESTE</h2>';
$mail->AltBody = 'Enviando emails com PHPMailer para TESTE';

$send = $mail->Send();

if($send) {
    echo 'E-mail enviado com sucesso!';
} else {
    echo 'Erro: ' . $mail->ErrorInfo;
}

?>
    
asked by anonymous 24.11.2015 / 03:09

1 answer

1

Your code worked here in my test, the only thing I changed was how to do the PHPMailerAutoload.php class include.

require './PHPMailer/PHPMailerAutoload.php';

Considering that the PHPMailer directory is in the same directory as my .php file.

I recommend that you use a debug to detect errors, it is easier to understand where the problem is, so you can use the Debug of an IDE, such as Netbeans for example. I recommend the Atom editor , and PHP debug plugin , in my case it worked the best.

    
24.11.2015 / 12:00