Sending mail in PHP using Hotmail smtp

Blue Rose picture Blue Rose · Mar 13, 2014 · Viewed 25.8k times · Source

I am trying to send mail in PHP using Hotmail Smtp. But I am getting error as below:

2014-03-13 06:59:01 CLIENT -> SERVER: EHLO site.com 
2014-03-13 06:59:01 CLIENT -> SERVER: AUTH LOGIN 
2014-03-13 06:59:01 SMTP ERROR: AUTH command failed: 504 5.3.3 AUTH mechanism LOGIN not available 
2014-03-13 06:59:01 CLIENT -> SERVER: QUIT SMTP connect() failed. Mailer Error: SMTP connect() failed.

Please would anyone suggest me what I am doing wrong??

My code :

error_reporting(E_STRICT);
require_once('class.phpmailer.php');
include('class.smtp.php');
$mail             = new PHPMailer(); //Initialize a new PHPMailer object;
//$body            = preg_replace("[\]",'',$body); //Replace unwanted characters of the content
$mail->CharSet ="ISO-8859-1";//Set the character set you need to specify
$mail->IsSMTP(); // Use SMTP service
$mail->SMTPDebug  = 1;                     // Enable debugging for SMTP
// 1 = errors and messages
// 2 = messages only
$mail->From = '[email protected]';
$mail->FromName = 'Name';
$mail->SMTPAuth   = true;                
$mail->SMTPSecure = "SSL";                 
$mail->Host       = 'smtp.live.com';      
$mail->Port       = '465';                         


$mail->Username   = '[email protected]';            //Username of your email account
$mail->Password   = '***';                               //Password of your email account

$mail->SetFrom('[email protected]', 'Name');
$mail->AddReplyTo('[email protected]','Name');
$mail->Subject    = $subject;
$mail->AltBody    = 'To view the message, please use an HTML compatible email viewer!'; // optional, comment out and test
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, '');
//$mail->AddAttachment("images/phpmailer.gif");      // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

//var_dump($body);
if(!$mail->Send()) {
    //echo $body;

    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
   echo "Message sent successfully!";
}

Need help. thanks.

How would I solve this problem? Anyone's help would be appreciated.

Answer

Damian picture Damian · Jun 7, 2014

Below works for me:


    $mail = new PHPMailer();
    $mail->SMTPSecure = 'tls';
    $mail->Username = "[email protected]";
    $mail->Password = "mypassword";
    $mail->AddAddress("[email protected]");
    $mail->FromName = "My Name";
    $mail->Subject = "My Subject";
    $mail->Body = "My Body";
    $mail->Host = "smtp.live.com";
    $mail->Port = 587;
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->From = $mail->Username;
    $mail->Send();