我使用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 = "example@outlook.com";
$mail->Password = "password";
$mail->SMTPSecure = 'tls';
$mail->From = "info@neelcomputech.com";
$mail->FromName = $name;
$mail->AddAddress("info@neelcomputech.com");
$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';
}
?>
答案 0 :(得分:2)
<?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 = "info@neelcomputech.com"; // Your Email Address
$mail->Password = "YOUR PASSWORD"; // Your Password
$mail->SMTPSecure = 'tls'; // Check Your Server's Connections for TLS or SSL
$mail->From = "info@neelcomputech.com";
$mail->FromName = $name;
$mail->AddAddress("info@neelcomputech.com");
$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';
}
?>
您必须在smtp身份验证中使用自己的参数。 您还可以在PHPMailer的网站上查看其他邮件服务器的smtp参数: phpmailer.worxware.com/index.php?pg=tip_srvrs
答案 1 :(得分:0)
您可以使用以下代码解决此问题:
$mail->Host = 'relay-hosting.secureserver.net';
答案 2 :(得分:0)
我花了很多时间来弄清楚CentOS 7默认禁用SMTP连接,而不是通过Firewalld。
尝试运行这些行,如果遇到此“邮件程序错误:以下发件人地址失败:”和“调用邮件()未连接”。
sudo setsebool -P httpd_can_sendmail 1
sudo setsebool -P httpd_can_network_connect 1