【发布时间】:2013-08-16 18:51:29
【问题描述】:
我已经写了这个表格,它工作得很好。它可以很好地发送电子邮件。但发送后,它会出错。所以提交表单的人认为它坏了,但它实际上发送了表单。我要做的就是在邮件发送后将表单提交到thanks.asp 后重定向。
任何帮助表示赞赏。
<?php
$name = trim($_POST['name']);
$company = $_POST['company'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$site_owners_email = 'support@macnx.com'; // Replace this with your own email address
$site_owners_name = 'Landin'; // replace with your name
if (strlen($name) < 2) {
$error['name'] = "Please enter your name";
}
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address";
}
if (strlen($comments) < 3) {
$error['comments'] = "Please leave a comment.";
}
if (!$error) {
require_once('phpMailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->From = $email;
$mail->FromName = $name;
$mail->Subject = "Website Contact Form";
$mail->AddAddress($site_owners_email, $site_owners_name);
$mail->Body = $email . $company . $comments;
// GMAIL STUFF
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "inquiry@getgearhead.com"; // SMTP username
$mail->Password = "..."; // SMTP password
$mail->Send();
header("Location: http://www.macnx.com/noflash/thanks.asp");
}
?>
【问题讨论】:
-
报错应该是headers已经发送了。
-
请把错误贴出来让我们看看
-
正如@ChrisB 所说,检查您是否在
<?php或HTML 或任何其他类型的输出之外或之上有空格。如果不是这样,那么这是一个字节顺序标记问题。 -
如果消息是Hi,这会失败吗?来吧伙计,我只是想说 嗨。
-
这只是一个常规的 500 错误。我要检查 php 日志
标签: php