<?php
require '/etc/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "my@gmail.com";
$mail->Password = "password";
$mail->SetFrom("from@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("to@gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>这是我的邮件功能代码&它给出了错误
SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No address associated with hostname我的php.ini文件中没有extension=php_openssl.dll,但我仍然包含了这个和相同的问题
发布于 2015-06-24 20:12:35
为了避免动态IP的问题(每次我ping smtp.gmail.com,我都会看到最后3位数字的细微差别),你只需要使用php内置的gethostbyname()来实时读取IP。
$smtp_host_ip = gethostbyname('smtp.gmail.com');然后使用它作为主机。希望能有所帮助。
https://stackoverflow.com/questions/31025915
复制相似问题