Phpmailer works with Gmail but not with Hotmail/Live

Asked

Viewed 628 times

1

I have the following code:

<?php
require'PHPMailerAutoload.php';

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Port = '465';
$mail->Host = 'smtp.gmail.com'; 
$mail->IsHTML(true); 
$mail->Mailer = 'smtp'; 
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true; 
$mail->Username = '[email protected]'; 
$mail->Password = 'senhadoemail';
$mail->SingleTo = true; 

$mail->From = "[email protected]"; 
$mail->FromName = "nomedousuario"; 
$mail->addAddress("[email protected]");
$mail->Subject = "assunto do email"; 
$mail->Body = "conteudo do email";

if(!$mail->Send()){
    echo "Erro ao enviar Email:" . $mail->ErrorInfo;
}else{
    echo "Mensagem enviada com sucesso!"
}
?>

This code works normally by sending emails from a sender who has a Gmail account to any other account, the problem is that when switching to Live/Hotmail it does not work. The changes I tried to make were as follows:

$mail->Host = 'smtp.live.com'; 

$mail->SMTPSecure = 'tsl';

I also changed the sender’s email to the end @Hotmail.com. The mistake I get is: SMTP connection failed(). I run this code on localhost and wonder what I’m doing wrong.

  • in fact this question is about e-mail using live/Hotmail, even because using gmail the code is in full operation

  • Roberto, I adjusted the title to reflect what I understood to be your problem. Try to make headlines that quickly describe the problem; "Help with X" doesn’t explain anything to anyone who sees your question on the main page.

  • Oh yes, I thought the problem was the same. I already deleted the comment.

1 answer

0

Activate the Debug:

$mail->SMTPDebug  = 2;

Smtpsecure is not tsl. is yes tls':

 $mail->SMTPSecure = 'tls';

When I send to the hotel I need to change the door to 587:

 $mail->Port = 587;

Standard sending example taken from the documentation of Phpmailer on Github:

<?php 

require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.live.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'XXXXXXXX';                 // SMTP username
$mail->Password = 'XXXXXXXX';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('XXXXXXXXhotmail.com', 'Mailer');
$mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
  • I tried these changes and still could not send the email, the error is now code 550.

  • If you can post a piece of your code here, it would be very useful

  • @Roberto reedited the answer with an example.

Browser other questions tagged

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