使用 Hotmail smtp 在 PHP 中发送邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22371724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending mail in PHP using Hotmail smtp
提问by Blue Rose
I am trying to send mail in PHP using Hotmail Smtp. But I am getting error as below:
我正在尝试使用 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.
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.
我将如何解决这个问题?任何人的帮助将不胜感激。
回答by Damian
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();
回答by Merch
Windows Live Mail uses port 587(TLS enabled) not the standard 465.
Windows Live Mail 使用端口 587(启用 TLS)而不是标准的 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.
也就是说,不只是使用您的主机本地 smtp 服务器?这样您就不必进行身份验证(或收集发件人密码),您仍然可以将发件人地址设置为他们的 Hotmail。
$mail->SMTPSecure = "tls";

