本文介绍了SMTP连接()失败...当我尝试从我的php文件发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试从我的php文件发送邮件,我收到这样的错误 **SMTP错误:无法连接到服务器:php_network_getaddresses:getaddrinfo失败:没有这样的主机是已知的(0)SMTP连接()失败。**
我在我的项目的最后期限,如果有人知道我在这里做了什么解决方案或错误,请分享和帮助。
i我在这里分享我的代码.........
<?php
要求( C:/xampp/htdocs/conference/PHPMailer-master/class.phpmailer.php);
require(C:/xampp/htdocs/conference/PHPMailer-master/class.smtp.php);
$ mail = new PHPMailer();
$ mail-> IsSMTP(); //告诉班级使用SMTP
$ mail-> SMTPDebug = 1; // debugging:1 = errors and messages,2 = messages only
$ mail-> SMTPAuth = true; // SMTP authentication
$ mail-> SMTPSecure ='tls'; //安全传输启用要求GMail
$ mail-> Host =smtp.gmail.com; // SMTP server
$ mail-> Port = 465; // SMTP Port
$ mail-> Username =我的电子邮件地址; // SMTP帐户用户名
$ mail-> Password =我的密码; // SMTP帐户密码
$ mail-> SetFrom('我的电子邮件地址','xxxx'); // FROM
$ mail-> AddReplyTo('我的电子邮件地址','xxxx'); //回复TO
$ mail-> AddAddress('someone email address','yyyy'); //收件人电子邮件
$ mail-> Subject =First SMTP Message; // email subject
$ mail-> Body =嗨!\\\
\\\
这是我通过使用PHPMailer的Google SMTP发送的第一封电子邮件。
if(!$ mail-> Send()){
echo'消息未发送。
echo'Mailer error:'。 $ MAIL-> ERRORINFO;
} else {
echo'已发送消息。
}
?>
解决方案
我发现这个问题的解决方案
检查您的PHP是否使用 openSSL 扩展程序...!
- 从您安装的php文件夹中编辑您的 php.ini
- 搜索 extension = php_openssl.dll
- 初始化将看起来像这样; extension = php_openssl.dll
- 删除';',它看起来像这样 extension = php_openssl.dll
- 如果找不到 extension = php_openssl.dll ,请添加此行 extension = php_openssl.dll 。
- 然后重新启动您的Xampp或LAMP或APACHE服务器(取决于您使用的是哪一个)。
- 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).
希望这个方法可以解决你的问题...
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.';
}
?>
解决方案
I found a solution for this problem,
Check whether your PHP is using openSSL extension or not...!
Hope this method would solve your problem...
这篇关于SMTP连接()失败...当我尝试从我的php文件发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!