PHPMailer error connecting

1

I'm trying to send an email from my Localhost , but I can not.

My code:

<?php
require_once('config/phpmailer/class.phpmailer.php');
//
//$email = $_POST["email"];
//
$mail = new PHPMailer();
//
$mail->IsSMTP(true); 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 587;
$mail->SMTPAuth = true; 
$mail->SMTPDebug = 1;
$mail->SMTPSecure = 'ssl';
$mail->Username = '[email protected]'; 
$mail->Password = 'mypassword';
//
$mail->From = "mygmail";
$mail->FromName = "hello";
//
$mail->AddAddress($email, 'assunto');
$mail->IsHTML(true); 
$mail->Subject  = "hello!"; 
$mail->Body = "oi teste";
$enviado = $mail->Send();
$mail->ClearAllRecipients();
$mail->ClearAttachments();
if ($enviado) {
  $error = "E-mail enviado com sucesso!";
}
else {
  echo "Não foi possível enviar o e-mail.";
  $error = "<b>Informações do erro:</b> " . $mail->ErrorInfo;
}

?>

Error:

The following From address failed: [email protected] : Called Mail() without being connected

I have already released the account for devices in google, already tried to change ssl to tls as well. The email and password are also correct.

    
asked by anonymous 15.12.2017 / 01:14

0 answers