0

再会!

我从 Google 代码页下载了 PHPMailer 类:http ://code.google.com/a/apache-extras.org/p/phpmailer/ 。我正在运行这个:

PHP 5.2.14 (cli) (built: Jul 27 2010 10:49:36)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

在 Windows 7 机器上,我正在使用以下测试代码:

require("PHPMailer_5.2.1/class.phpmailer.php");

$mail = new PHPMailer();  

$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.live.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "some_email@hotmail.nl";
$mail->Password = "password";

$mail->From     = "some_email@hotmail.nl";
$mail->AddAddress("some_other_email@hotmail.nl");  

$mail->Subject  = "Subject";
$mail->Body     = "Hi!";

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';

我也确定密码和用户名是正确的,但我收到以下错误:

Message was not sent.Mailer error: The following From address failed: some_email@hotmail.nl

我究竟做错了什么?

提前致谢!

4

1 回答 1

2

我不使用 live.com,所以我用我的 gmail 帐户测试了你的脚本,它运行良好。您可以确保为您的 live.com 帐户设置了正确的用户名和密码。或者你可以尝试设置$mail->SMTPSecure = 'tls'; 这适用于 gmail:

require("PHPMailer_5.2.1/class.phpmailer.php");
$mail = new PHPMailer();  
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Username = "yourNickname@gmail.com";
$mail->Password = "yourPassword";
$mail->From     = "some_email@hotmail.nl";
$mail->AddAddress("receiver@server.ext");
$mail->Subject  = "Subject";
$mail->Body     = "Hi!";
if(!$mail->Send()) {
    echo 'Message was not sent.';
    echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent.';
}
于 2012-08-12T10:30:48.543 回答