【发布时间】:2013-06-26 04:54:15
【问题描述】:
我正在尝试让用户填写联系表格,然后将其发送到我的电子邮件中。但由于某种原因它不起作用。我只是得到一个空白页,没有错误消息或任何文本和电子邮件也没有发送。
if (isset($_POST['submit']))
{
include_once('class.phpmailer.php');
$name = strip_tags($_POST['full_name']);
$email = strip_tags ($_POST['email']);
$msg = strip_tags ($_POST['description']);
$subject = "Contact Form from DigitDevs Website";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.example.com"; // SMTP server example
//$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "info@example.com"; // SMTP account username example
$mail->Password = "password"; // SMTP account password example
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress('info@example.com', 'Information');
$mail->AddReplyTo($email, 'Wale');
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
【问题讨论】:
-
检查服务器日志,找出问题所在。
-
您使用的是哪个操作系统?如果是
Ubuntu,如果邮件发送失败,那么在您的Web 根目录中将创建一个名为dead.letter的文件,一旦检查。 -
尝试在'exit;'之后插入'}'
-
或在最后一个'echo'之后?
-
@AmalMurali 这是我在日志中得到的:[28-Jun-2013 11:57:02 UTC] PHP 致命错误:require_once() [ function.require]:在 /home/digitdev/public_html/ 中打开所需的 'class.smtp.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') 失败第 1004 行的 class.phpmailer.php