PHPMailer无法连接到SMTP主机

前端之家收集整理的这篇文章主要介绍了PHPMailer无法连接到SMTP主机前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
得到以下错误

SMTP -> ERROR: Failed to connect to server: PHP_network_getaddresses: getaddrinfo Failed: No such host is known. (0)
SMTP Error: Could not connect to SMTP host. There was a problem sending this mail!

这是我的配置文件设置,因为我遵循了这个PHPMailer tutorial

// Configuration settings for My Site

// Email Settings
$site['from_name'] = 'Manish Dekavadiya'; // from email name
$site['from_email'] = 'manish@<my-domain>.com'; // from email address

// Just in case we need to relay to a different server,// provide an option to use external mail server.
$site['smtp_mode'] = 'enabled'; // enabled or disabled
$site['smtp_host'] = "smtp.<my-domain>.com";
$site['smtp_port'] = 587;
$site['smtp_username'] = "manish@<my-domain>.com";
$site['smtp_password']="<password>";

并使用了mailer类和教程中提到的扩展类如下:

/*****sendmail.PHP****/

// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.PHP');

// Grab the FreakMailer class
//echo $_SERVER['DOCUMENT_ROOT'];
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');

// instantiate the class
$mailer = new FreakMailer();

// Set the subject
$mailer->Subject = 'This is a test';
 $mailer->SMTPDebug = 1;
// Body
$mailer->Body = 'This is a test of my mail system!';

// Add an address to send to.
$mailer->AddAddress('manish.dekavadiya@gmail.com','Manish Dekavadiya');

if(!$mailer->Send())
{
    echo 'There was a problem sending this mail!';
}
else
{
    echo 'Mail sent!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();

当我尝试在PHPmailer docs @ examples / test_smtp_gmail_basic.PHP中给出的示例时,还会出现另一个错误

SMTP -> ERROR: Failed to connect toserver: PHP_network_getaddresses:
getaddrinfo Failed: No such host is
known. (0) SMTP Error: Could not
connect to SMTP host. There was a
problem sending this mail!

所以必须有设置或配置错误.没有代码错误.

是否设置了SMTP?如果是这样,它被配置为在端口587上收听smtp..com?如果服务器没有自己设置,那么他们收听mail..com的情况并不少见.此外,尝试连接到端口25以查看是否可以将其配置为侦听默认的smtp端口.

在任何情况下,错误消息都非常清楚.主机未响应您的连接尝试.原因可能是服务器和PHP中的配置错误,防火墙问题,路由问题,DNS问题等.

原文链接:https://www.f2er.com/php/134982.html

猜你在找的PHP相关文章