表单成功后重定向到不同的 URL

我有一个使用 PHPMailer 的基本表单页面:


一切正常并发送到相关电子邮件,但是我想在成功消息出现后将用户推送到另一个页面,以便我可以在这个新页面上添加一些跟踪代码。


任何帮助,将不胜感激。


这是代码:


 <?php


require_once('phpmailer/PHPMailerAutoload.php');


$toemails = array();


$toemails[] = array(

    'email' => 'test@test.com', // Your Email Address

    'name' => 'Some type of name' // Your Name

);


// Form Processing Messages

$message_success = 'We have <strong>successfully</strong> received your Message and will get Back to you as soon as possible.';


// Add this only if you use reCaptcha with your Contact Forms

$recaptcha_secret = 'your-recaptcha-secret-key'; // Your reCaptcha Secret


$mail = new PHPMailer();


// If you intend you use SMTP, add your SMTP Code after this Line



if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    if ($_POST['template-contactform-email'] != '') {


        $name  = isset($_POST['template-contactform-name']) ? $_POST['template-contactform-name'] : '';

        $email = isset($_POST['template-contactform-email']) ? $_POST['template-contactform-email'] : '';

        $phone = isset($_POST['template-contactform-phone']) ? $_POST['template-contactform-phone'] : '';


        $subject = isset($_POST['template-contactform-subject']) ? $_POST['template-contactform-subject'] : '';



        $subject = isset($subject) ? $subject : 'Ladies Boxing Offer';


        $botcheck = $_POST['template-contactform-botcheck'];




  

慕森王
浏览 153回答 2
2回答

莫回无

你可以把这一行放在你的代码中:echo "<script>window.location='successPage.php'</script>";从而成为成功的一部分:if ($sendEmail == true):&nbsp; echo '{ "alert": "success", "message": "'.$message_success.'" }';&nbsp; echo "<script>window.location='successPage.php'</script>";else :&nbsp; echo '{ "alert": "error", "message": "Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />'.$mail - > ErrorInfo.'" }';endif;

尚方宝剑之说

你可以试试:if ($sendEmail == true):&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '{ "alert": "success", "message": "' . $message_success . '" }';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; die('<script type="text/javascript">window.location.href=somepage.html;</script>');或者if ($sendEmail == true):&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '{ "alert": "success", "message": "' . $message_success . '" }';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; header('Location: somepage.html');
打开App,查看更多内容
随时随地看视频慕课网APP