为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
慕森王 2021-06-29 16:00:27
我有一个使用 PHPMailer 的基本表单页面:一切正常并发送到相关电子邮件,但是我想在成功消息出现后将用户推送到另一个页面,以便我可以在这个新页面上添加一些跟踪代码。任何帮助,将不胜感激。这是代码: <?phprequire_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 Lineif ($_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'];  
查看完整描述

2 回答

?
莫回无

TA贡献1865条经验 获得超7个赞

你可以把这一行放在你的代码中:


echo "<script>window.location='successPage.php'</script>";

从而成为成功的一部分:


if ($sendEmail == true):

  echo '{ "alert": "success", "message": "'.$message_success.'" }';

  echo "<script>window.location='successPage.php'</script>";


else :

  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;


查看完整回答
反对 回复 2021-07-09
?
尚方宝剑之说

TA贡献1788条经验 获得超4个赞

你可以试试:


if ($sendEmail == true):

                echo '{ "alert": "success", "message": "' . $message_success . '" }';

                die('<script type="text/javascript">window.location.href=somepage.html;</script>');

或者


if ($sendEmail == true):

                echo '{ "alert": "success", "message": "' . $message_success . '" }';

                header('Location: somepage.html');


查看完整回答
反对 回复 2021-07-09
  • 2 回答
  • 0 关注
  • 152 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信