我试图在PHP中使用Hotmail Smtp发送邮件。但是我得到的错误如下:
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!";
}
需要帮助。谢谢。
我该如何解决这个问题?
下面的内容适合我:
<>之前$mail = new PHPMailer();$mail->SMTPSecure = 'tls';$mail->Username = "mymail@hotmail.com";$mail->Password = "mypassword";邮件-> AddAddress("mymail@hotmail.com");$mail->FromName = "我的名字";$mail->Subject = "My Subject";$mail->Body = "My Body";$mail->Host = "smtp.live.com";$mail->端口= 587;邮件-> IsSMTP ();$mail->SMTPAuth = true;$mail->From = $mail->Username;邮件->发送();Windows Live Mail使用的端口是587(启用TLS),而不是标准的465。
这就是说,为什么不直接使用您的主机本地smtp服务器?这样你就不需要认证(或收集发件人密码),你仍然可以将发件人地址设置为他们的Hotmail。
$mail->SMTPSecure = "tls";