使用Hotmail smtp在PHP中发送邮件

时间:2014-03-13 07:20:40

标签: php email smtp hotmail

我正在尝试使用Hotmail Smtp在PHP中发送邮件。但我收到的错误如下:

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.

请有人建议我做错了吗?

我的代码:

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!";
}

需要帮助。感谢。

我该如何解决这个问题?任何人的帮助将不胜感激。

2 个答案:

答案 0 :(得分:3)

以下对我有用:


    $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();

答案 1 :(得分:0)

Windows Live Mail使用端口587(启用TLS)而非标准465。

那说不只是使用你的主机本地smtp服务器?这样您就不必进行身份验证(或收集发件人密码),您仍然可以将发件人地址设置为Hotmail。

$mail->SMTPSecure = "tls";