我正在使用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';
}
?>