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:
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!