【发布时间】:2014-12-21 01:23:12
【问题描述】:
我一直在尝试使用 phpmailer 类测试从 php 发送电子邮件。我的配置是这样的:
require '../php/library/class.phpmailer.php';
require '../php/library/class.smtp.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = "anactual@email.com";
$mail->Password = "thepassword";
$mail->setFrom('existing@gmail.com', 'Real Name');
$mail->addAddress( $validEmail );
$mail->Subject = 'Confirmation Code';
$mail->msgHTML('Follow this link: <a href="http://test.com/confirm?code=' . $newAccount->confirmationCode . '">http://test.com/confirm?code=' . $newAccount->confirmationCode . '</a>');
$mail->AltBody = 'This is a plain-text message body with this link: http://test.com/confirm?code=' . $newAccount->confirmationCode;
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
但是,事情似乎不起作用,我只是复制粘贴了 gmail 示例中的代码。我已经在万维网上搜索了错误输出:
SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
SMTP connect() failed.
Mailer Error: SMTP connect() failed.
但仍然无法找出问题所在。请问有什么帮助吗?
更新我已禁用 gmail 中的两步验证
【问题讨论】:
-
我在这里的评论并不完全是关于 phpmailer 的。我认为 Mantis 邮件系统正在使用 phpmailer,我必须承认自 10 月以来我面临同样的问题 - 我的服务器上没有更改任何配置,但是不再发送电子邮件通知。
-
这是一个unix服务器吗?
-
@ksealey fedora core 20
-
这是一个 DNS 问题。搜索“php_network_getaddresses:getaddrinfo”的堆栈溢出,您将找到有关此错误的更多信息,以及导致它的原因。您是否在 /etc/resolv.conf 中配置了可用的 DNS 服务器?在命令行中,如果您执行 nslookup smtp.gmail.com,它会解决吗?如果是这样,请尝试重新启动 apache,这可能会解决问题。