PHPMailer works with Gmail but not with Hotmail / Live [duplicate]

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, sending emails from a sender that has a Gmail account to any other account, the problem is that switching to Live / Hotmail 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 @ hotmail.com . The error I get is: SMTP connection failed() . I ran this code in localhost and would like to know what I'm doing wrong.

    
asked by anonymous 20.11.2015 / 14:32

1 answer

0

Enable Debug:

$mail->SMTPDebug  = 2;

SMTPSecure is not 'tsl'. is yes 'tls':

 $mail->SMTPSecure = 'tls';

When I'm going to send to hotmail I need to change the port to 587:

 $mail->Port = 587;

Example of default submission caught in Phpmailer documentation in 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';
}
    
20.11.2015 / 16:16