php 邮件程序错误:以下发件人地址失败:在未连接的情况下调用 Mail()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23776256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mailer Error: The following From address failed: Called Mail() without being connected
提问by Jeeten Parmar
I am using PHPMailer
using SMTP
to send Email. I have set everything.
But in the last I am getting error :Mailer Error: The following From address failed: Email Address : Called Mail() without being connected
I came to know to set Order of coding, I also did it but still same error. Please help me to solve this issue.
My Code :
我使用PHPMailer
用SMTP
发送电子邮件。我已经设置了一切。
但在最后我收到错误:Mailer Error: The following From address failed: Email Address : Called Mail() without being connected
我开始知道设置编码顺序,我也这样做了,但仍然是同样的错误。请帮我解决这个问题。
我的代码:
<?php
require 'PHPMailer.php';
error_reporting(E_ALL);
ini_set('display_errors', '1');
$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->SMTPSecure = 'tls';
$mail->From = "[email protected]";
$mail->FromName = $name;
$mail->AddAddress("[email protected]");
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $mail_body = "<html> <body>";
$mail_body = "<b>Hello Admin,</b><br><br>You have got email from your website.<br><br>";
$mail_body .= '<table style="" cellpadding="3">';
$mail_body .= "
<tr>
<td width='50'> <strong> Name </strong> </td>
<td width='5'> : </td>
<td> $name </td>
</tr>
<tr>
<td> <strong> Email </strong> </td>
<td> : </td>
<td> $email </td>
</tr>
<tr>
<td> <strong> Message </strong> </td>
<td> : </td>
<td> $message </td>
</tr>
</table>
</body> </html>";
if(!$mail->Send())
{
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
echo 'success';
}
?>
采纳答案by HddnTHA
<?php
require 'PHPMailer.php';
error_reporting(E_ALL);
ini_set('display_errors', '1');
$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.neelcomputech.com"; // Your SMTP PArameter
$mail->Port = 587; // Your Outgoing Port
$mail->SMTPAuth = true; // This Must Be True
$mail->Username = "[email protected]"; // Your Email Address
$mail->Password = "YOUR PASSWORD"; // Your Password
$mail->SMTPSecure = 'tls'; // Check Your Server's Connections for TLS or SSL
$mail->From = "[email protected]";
$mail->FromName = $name;
$mail->AddAddress("[email protected]");
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $mail_body = "<html> <body>";
$mail_body = "<b>Hello Admin,</b><br><br>You have got email from your website.<br><br>";
$mail_body .= '<table style="" cellpadding="3">';
$mail_body .= "
<tr>
<td width='50'> <strong> Name </strong> </td>
<td width='5'> : </td>
<td> $name </td>
</tr>
<tr>
<td> <strong> Email </strong> </td>
<td> : </td>
<td> $email </td>
</tr>
<tr>
<td> <strong> Message </strong> </td>
<td> : </td>
<td> $message </td>
</tr>
</table>
</body> </html>";
if(!$mail->Send())
{
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
echo 'success';
}
?>
You have to use your own parameters, in your smtp authentication. Also you can check other mail server's smtp parameters on PHPMailer's Website: phpmailer.worxware.com/index.php?pg=tip_srvrs
您必须在 smtp 身份验证中使用自己的参数。您也可以在 PHPMailer 的网站上查看其他邮件服务器的 smtp 参数: phpmailer.worxware.com/index.php?pg=tip_srvrs
回答by suraj
You could resolve this by using the following code:
您可以使用以下代码解决此问题:
$mail->Host = 'relay-hosting.secureserver.net';
$mail->Host = 'relay-hosting.secureserver.net';
回答by Donzo
It took me a lot of digging to figure out the CentOS 7 disables SMTP connections by default, and its not through Firewalld.
我花了很多时间才弄清楚 CentOS 7 默认禁用 SMTP 连接,而不是通过 Firewalld。
Try running these lines if you run into this " Mailer Error: The following From address failed: " and "Called Mail() without being connected."
如果您遇到此“邮件程序错误:以下发件人地址失败:”和“未连接的情况下调用 Mail()”,请尝试运行这些行。
sudo setsebool -P httpd_can_sendmail 1
须藤 setsebool -P httpd_can_sendmail 1
sudo setsebool -P httpd_can_network_connect 1
须藤setebool -P httpd_can_network_connect 1
Thanks to the following web article: https://gistpages.com/posts/phpmailer_smtp_error_failed_to_connect_to_server_permission_denied_13_fix
感谢以下网络文章:https: //gistpages.com/posts/phpmailer_smtp_error_failed_to_connect_to_server_permission_denied_13_fix