【问题标题】:Error SMTP: Failed to connect socket: php_network_getaddresses: getaddrinfo failed: Name or service not known错误 SMTP:无法连接套接字:php_network_getaddresses:getaddrinfo 失败:名称或服务未知
【发布时间】:2018-03-07 15:25:19
【问题描述】:

我收到 SMTP 错误:“错误 SMTP:无法连接套接字:php_network_getaddresses:getaddrinfo 失败:名称或服务未知”

这是我的代码

$from = "examplewebsite.com";

邮寄

$to = "example@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

主机名

$host = "website.com ";
$username = "info@website.com";
$port = "465";
$password = "password";

标题

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

数组中的信息

$smtp = Mail::factory(
    'smtp',
    array (
        'host' => $host,
        'port' => $port,
        'auth' => true,
        'username' => $username,
        'password' => $password
    )
);

邮件功能

$mail = $smtp->send($to, $headers, $body);

梨形检查和错误信息

if (PEAR::isError($mail)) {
    echo($mail->getMessage());  
} 
else {   
    echo("Message successfully sent!");  
}

【问题讨论】:

    标签: php smtp


    【解决方案1】:

    这是一个DNS故障,可能是$host = "website.com ";中的杂散空间导致它查找一个不存在的域。

    【讨论】:

    • 它显示错误agian Failed to connect to website.com:465 [SMTP: Failed to connect socket: Connection timed out (code: -1, response: )]
    • 连接到端口 465 意味着您正在使用 SSL,但在您的配置中没有任何迹象。我怀疑您是否需要在 $host 中指定 smtp - 这将是一个奇怪的地方。你总是可以(在这里只是一个疯狂的猜测)尝试reading the docs...
    • 你能告诉我如何用我现有的代码编写 smtp
    【解决方案2】:

    我只是在我的代码中添加这些行并解决了问题

    $host = "ssl://websitename.com";
    $username = "username";
    $password = "password";
    $port = "465";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-26
      • 2019-06-07
      • 2021-02-27
      • 2023-03-29
      • 2017-02-21
      • 2013-12-02
      • 2016-02-07
      相关资源
      最近更新 更多