PHP Mailer SMTP - Does not work

Asked

Viewed 324 times

0

The code I have is this::

require_once ( 'class.phpmailer.php' );
$Mail = new PHPMailer();

$Mail->IsSMTP(); 
$Mail->Host        = ""; // O QUE COLOCAR AQUI??
$Mail->SMTPDebug   = 0; // 2 to enable SMTP debug information
$Mail->SMTPAuth    = TRUE; 
$Mail->SMTPSecure  = "ssl"; 
$Mail->Port        = 465; 
$Mail->Username    = '[email protected]'; 
$Mail->Password    = 'minhapass'; 
$Mail->Priority    = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From        = '[email protected]';
$Mail->AddAdress    = ('[email protected]'); 
$Mail->WordWrap    = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->isHTML( TRUE );
$Mail->SMTPDebug   = 1;

$Mail->Body  = "corpo";
$Mail->AddAddress("[email protected]"); // To: 
$Mail->Send();

Thank you

1 answer

4


Missing indicate which host will send the message, I think for Gmail is "smtp.gmail.com":

$Mail->Host = "smtp.gmail.com";

If it doesn’t work, enable debug mode:

$Mail->SMTPDebug   = 1;

Also change the last line:

$Mail->Send();

By that code:

if(!$Mail->Send()) { 
    echo "Mailer Error: " . $Mail->ErrorInfo; 
} else { 
    echo "Enviado com sucesso!"; 
}

Change your question and post the error that is returned, so we will have more information.

  • Thanks @Filipe Moraes was already working. But now it’s wrong.

  • @Claudia the error says that the password is not correct. Have you changed the password of the email? If yes have to change the code also.

  • i did not change the email password.

  • Now you’re making a different mistake. I’ve updated the question.

  • @Claudia change your question and put the PHP code you are currently using, so I see the current one is out of date.

  • the question code is already updated. Thank you

  • I’ve solved my problem. Thank you

  • @Claudia that’s great! The problem now is that the answer is out of date. Looking at the question and the answer, it will not solve the problem of who got the same error. What was the solution you found? If it was something specific, at least put the question back in its initial state.

  • you’re right! I’ve put the question in the initial state.

Show 4 more comments

Browser other questions tagged

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