问题
i ve been trying to send mail from my php file, i got an error like this
**"SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) SMTP connect() failed."**
i am in the deadline of my project, if anybody knows the solution or error what i have done over here, please share and help. i am sharing my code here.........
<?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.';
}
?>
回答1:
I found a solution for this problem,
Check whether your PHP is using openSSL extension or not...!
- Edit your php.ini from your installed php folder
- Search for extension=php_openssl.dll
- The initial will look like this ;extension=php_openssl.dll
- Remove the ';' and it will look like this extension=php_openssl.dll
- If you can't find the extension=php_openssl.dll, add this line extension=php_openssl.dll.
- Then restart your Xampp or LAMP or APACHE server (depends upon which of these you're using).
Hope this method would solve your problem...
回答2:
There are double quotes in
$mail->Host = "smtp.gmail.com"; // SMTP server
Please remove the double quotes.
$mail->Host = 'smtp.gmail.com'; // SMTP server
来源:https://stackoverflow.com/questions/19111887/smtp-connect-failed-while-i-am-trying-to-send-mail-from-my-php-file