【问题标题】:Form submission redirect instead of echoing success message?表单提交重定向而不是回显成功消息?
【发布时间】:2013-10-17 10:29:30
【问题描述】:

我目前正在使用 PHP 表单处理器来发送带有表单字段的电子邮件。我想转换这个处理器,以便在成功提交后它将您重定向到不同的页面,而不是回显成功消息(就像现在一样)。下面是我用于处理器的代码。提前致谢!

<?php
if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "your@email.com";
    $email_subject = "Email Subject Goes Here";


    $organization_name_field = $_POST['organization'];  //required
    $contact_name_field = $_POST['name'];       //required
    $city_field = $_POST['city'];           //not required
    $state_field = $_POST['state'];           //not required
    $zipcode_field = $_POST['zip'];           //not required
    $email_field = $_POST['email'];           //not required
    $phone_number_field = $_POST['phone'];        //not required
    $email_message = "Form details below:\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Organization Name: ".clean_string($organization_name_field)."\n";
    $email_message .= "Contact Name: ".clean_string($contact_name_field)."\n";
    $email_message .= "City: ".clean_string($city_field)."\n";
    $email_message .= "State: ".clean_string($state_field)."\n";
    $email_message .= "Zip Code: ".clean_string($zipcode_field)."\n";   
    $email_message .= "Email: ".clean_string($email_field)."\n";
    $email_message .= "Telephone: ".clean_string($phone_number_field)."\n";


// create email headers
$headers = 'From: '.$contact_name_field."\r\n".
'Reply-To: '.$email_field."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
?>

【问题讨论】:

  • 只需添加 header('Location: someotherpage.php'); 而不是谢谢...
  • 永远不要使用那些抑制错误的@s!请检查mail 函数的状态以查看消息是否正确发送(到 SMTP 服务器)。
  • 电子邮件正确发送,我只是无法将表单重定向到感谢页面。

标签: php forms email redirect


【解决方案1】:

替换以下内容:

?>

<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
?>

与:

//Redirect user to another page
header('Location: email-success.php'); //Replace email-success.php with the page you want them to be redirected to!
}
?>

【讨论】:

    猜你喜欢
    • 2020-06-12
    • 1970-01-01
    • 2013-12-08
    • 2019-07-10
    • 2013-05-03
    • 2022-11-10
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多