错误SMTP:无法连接套接字:php_network_getaddresses:getaddrinfo failed:名称或服务未知

时间:2017-09-26 11:56:53

标签: php smtp

我收到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!");  
}

2 个答案:

答案 0 :(得分:0)

这是DNS失败,可能是由$host = "website.com ";中的杂散空间引起的,导致它查找不存在的域。

答案 1 :(得分:0)

我只是在我的代码中添加这些行并发布已解决的

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