我一直在試圖從我的PHP文件發送郵件發送郵件,我有這樣的SMTP連接()失敗......而我想從我的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.';
}
?>
嘗試更改端口號爲587,並重新啓動服務器 – jayadevkv