Sending mail in PHP using Hotmail smtp

2019-06-10 03:15发布

问题:

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 = 'abc@hotmail.com';
$mail->FromName = 'Name';
$mail->SMTPAuth   = true;                
$mail->SMTPSecure = "SSL";                 
$mail->Host       = 'smtp.live.com';      
$mail->Port       = '465';                         


$mail->Username   = 'abc@hotmail.com';            //Username of your email account
$mail->Password   = '***';                               //Password of your email account

$mail->SetFrom('abc@hotmail.com', 'Name');
$mail->AddReplyTo('abc@hotmail.com','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.

回答1:

Below works for me:


    $mail = new PHPMailer();
    $mail->SMTPSecure = 'tls';
    $mail->Username = "mymail@hotmail.com";
    $mail->Password = "mypassword";
    $mail->AddAddress("mymail@hotmail.com");
    $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();



回答2:

Windows Live Mail uses port 587(TLS enabled) not the standard 465.

That said wht not just use your hosts local smtp server? That way you won't have to auth (or collect the senders password) and you can still set the senders address as their Hotmail.

$mail->SMTPSecure = "tls";