PHPMailer提交后不重定向

时间:2015-07-17 12:06:28

标签: php phpmailer

代码在发送邮件和自动回复访问者时正常工作。但是,当提交表单时,页面不执行任何操作,只是位于同一页面上,表单仍然填写完整。它没有重定向到浏览器到#34;谢谢你"页。

我花了好几个小时试图解决这个问题,并且不能解释为什么它不会重定向。

请有人帮忙!

<?php
require $_SERVER['DOCUMENT_ROOT'].'/assets/class.phpmailer.php';
session_start();

date_default_timezone_set('Europe/London');
$time = date("d/m/y @ H:i:s", time());
$referer = $_SERVER['HTTP_REFERER'];
$ip = $_SERVER['REMOTE_ADDR'];

$sendfrom = "admin@example.com";
$sendname = "Senders Name";

$name = $_POST['visitor-name'];
$subject = $_POST['visitor-subject'];
$email = $_POST['visitor-email'];
$message = $_POST['visitor-message'];
$phone = $_POST['visitor-phone'];

$mail = new PHPMailer(true);
$mail->SMTPDebug = 0;
$mail->IsSMTP(true);
$mail->Host = "localhost"; //Hostname of the mail server
$mail->Port = '25'; //Port of the SMTP like to be 25, 80, 465 or 587
$mail->ClearReplyTos();
$mail->addReplyTo($email, $name);
$mail->SetFrom($sendfrom, $name); //FROM address and NAME
$mail->AddAddress($sendfrom); //TO address
$mail->Subject = ("Web Form: $subject");
$mail->Body = "MESSAGE";
$mail->IsHTML(true);

//auto reply
if($mail->send()){
    $automail = new PHPMailer(true);
    $automail->SMTPDebug = 0;
    $automail->IsSMTP(true);
    $automail->Host = "localhost"; //Hostname of the mail server
    $automail->Port = '25'; //Port of the SMTP like to be 25, 80, 465 or 587
    $automail->ClearReplyTos();
    $automail->addReplyTo("sales@example.com", $sendname);
    $automail->SetFrom($sendfrom, $sendname); //FROM address and NAME
    $automail->AddAddress($email); //TO address
    $automail->Subject = "Thank you for your recent enquiry";
    $automail->Body = "AUTO REPLY MESSAGE";

    $automail->IsHTML(true);

if($automail->Send()) {
    Header("Location: success.php");
    exit;
    }
}
?>

1 个答案:

答案 0 :(得分:1)

// $ mail-&gt; SMTPDebug = 0;

那帮助了我