3

我已经被困在这里将近一个星期了。我实际上遵循了教程中的步骤,但没有运气。我下载了这个phpmailer并获得了 5.4.2 版。下面的代码是这个下载的 phpmailer 的一个例子,但它对我不起作用。我已经配置了sendmailphp.ini。我还启用了一些扩展,例如php opensslphpsocket php smtp以及apache模块。我希望有人能帮助我解决这个问题,我希望。下面是我的代码:

<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>

<?php

error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('../class.phpmailer.php');
class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = "dasdf";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                       // 1 = errors and messages
                                       // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "gg@gmail.com";  // GMAIL username
$mail->Password   = "ggg";            // GMAIL password

$mail->SetFrom('gg@gmail.com', 'jj');

$mail->AddReplyTo("gg@gmail.com","jj");

$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "espadadave@yahoo.com";
$mail->AddAddress($address, "Dave");

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

?>

</body>
</html>
4

1 回答 1

2

该版本的 PHPMailer 非常过时(最后更新于 2013 年 2 月);它已被https://github.com/PHPMailer/PHPMailer取代

首先,您应该升级到最新版本;您很有可能正在尝试解决已修复的错误。

您会发现用法几乎相同;查看 GitHub 页面上的示例,了解当前版本的明显差异。

您还应该通过添加启用 SMTP 调试

$mail->SMTPDebug = 3;
于 2015-01-28T15:22:14.510 回答