我有这个表单,在本地发送正常,但当我上传到hostgator时,我收到以下错误消息
邮件程序错误:无法实例化邮件功能。
我的PHP代码是
<?php
if(isset($_POST['submit'])){
require 'PHPMailer/PHPMailerAutoload.php';
// Send mail
$mail = new PHPMailer();
// Data received from POST request
$name = stripcslashes($_POST['tbName']);
$emailAddr = stripcslashes($_POST['tbEmail']);
$company = stripcslashes($_POST['tbCompany']);
$comment = stripcslashes($_POST['taMessage']);
$subject = stripcslashes($_POST['tbSubject']);
// SMTP Configuration
$mail->SMTPAuth = true;
$mail->Host = "gator3209.hostgator.com"; // SMTP server
$mail->Username = "****@*****.com";
$mail->Password = "***********";
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->AddAddress('****@*****.com');
$mail->From = "****@*****.com";
$mail->FromName = "Website Contact Form - " . $name;
$mail->Subject = $subject;
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML("Name:" . $name . "<br /><br />Email:" . $emailAddr. "<br /><br />Company:" . $company. "<br /><br />Subject:" . $subject. "<br /><br />" . $comment);
$message = NULL;
if(!$mail->Send()) {
$message = "Mailer Error: " . $mail->ErrorInfo;
} else {
$message = "Message sent!";
}
}
?>
我已经和我的主人说过了,他们说这不是支持处理这些事情的,但我说我的端口和主机是正确的。
所以现在我很困惑。我有什么明显的遗失吗?
答案 0 :(得分:0)
只是为了让你知道,如果有人发现这个,我的问题是我错过了$ mail-&gt; IsSMTP();来自我的配置。
SMTP配置部分应如下
<?php
if(isset($_POST['submit'])){
require 'PHPMailer/PHPMailerAutoload.php';
// Send mail
$mail = new PHPMailer();
// Data received from POST request
$name = stripcslashes($_POST['tbName']);
$emailAddr = stripcslashes($_POST['tbEmail']);
$company = stripcslashes($_POST['tbCompany']);
$comment = stripcslashes($_POST['taMessage']);
$subject = stripcslashes($_POST['tbSubject']);
// SMTP Configuration
$mail->SMTPAuth = true;
$mail->IsSMTP();
$mail->Host = "gator3209.hostgator.com"; // SMTP server
$mail->Username = "****@*****.com";
$mail->Password = "***********";
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->AddAddress('****@*****.com');
$mail->From = "****@*****.com";
$mail->FromName = "Website Contact Form - " . $name;
$mail->Subject = $subject;
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML("Name:" . $name . "<br /><br />Email:" . $emailAddr. "<br /><br />Company:" . $company. "<br /><br />Subject:" . $subject. "<br /><br />" . $comment);
$message = NULL;
if(!$mail->Send()) {
$message = "Mailer Error: " . $mail->ErrorInfo;
} else {
$message = "Message sent!";
}
}
?>