我一直在尝试从我的 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.';
}
?>