>我一直在尝试从我的 PHP 文件发送邮件,我遇到了这样的错误
**"SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) SMTP connect() failed."**
我正处于项目的截止日期,如果有人知道我在这里所做的解决方案或错误,请分享和帮助。我在这里分享我的代码...
<?php
require("C:/xampp/htdocs/conference/PHPMailer-master/class.phpmailer.php");
require("C:/xampp/htdocs/conference/PHPMailer-master/class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // SMTP authentication
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 465; // SMTP Port
$mail->Username = "my email address"; // SMTP account username
$mail->Password = "my password"; // SMTP account password
$mail->SetFrom('my email address', 'xxxx'); // FROM
$mail->AddReplyTo('my email address', 'xxxx'); // Reply TO
$mail->AddAddress('someone email address', 'yyyy'); // recipient email
$mail->Subject = "First SMTP Message"; // email subject
$mail->Body = "Hi! 'n'n This is my first e-mail sent through Google SMTP using PHPMailer.";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
我找到了这个问题的解决方案,
检查您的PHP是否正在使用openSSL扩展...!
- 从已安装的 php 文件夹中编辑您的 php.ini
- 搜索扩展名=php_openssl.dll
- 首字母将如下所示;扩展名=php_openssl.dll
- 删除";",它将看起来像这个扩展名=php_openssl.dll
- 如果找不到扩展名=php_openssl.dll,请添加此行扩展名=php_openssl.dll。
- 然后重新启动您的 Xampp 或 LAMP 或 APACHE 服务器(取决于您使用的是哪一个)。
希望这种方法可以解决您的问题...
中有双引号
$mail->Host = "smtp.gmail.com"; // SMTP server
请删除双引号。
$mail->Host = 'smtp.gmail.com'; // SMTP server