1

好的,所以我想在填写完联系表后重定向到感谢页面。现在,它只是一个普通的、没有样式的谢谢,我希望它重定向到我设计的名为contact-thank-you.html的页面

这是我的 HTML 表单:

<form action="form_processor.php" method="post" >
        Name:<br /><input type="text" name="name" required="required" /><br /><br />
        E-mail:<br /><input type="text" name="email" required="required" /><br /><br />
        Message:<br /><textarea name="message" required="required"></textarea><br /><br />
        <input type="submit" value="Submit">
</form>

这是form_processor.php:

    $to      = 'myemail@email.com';
$subject = "New Message From Your Website";
$message = $_POST['message'];
$headers = 'From: ' . $_POST['name'] . ' <myemail@email.com>' . "\r\n" .
    'Reply-To: myemail@email.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

echo "Thank you, you message has been sent!";
4

5 回答 5

9

消除echo "Thank you, you message has been sent!";

因为自从您重定向页面后就没有必要拥有它,然后在完成所有交易后使用它来重定向

header('Location: contact-thank-you.html');
exit();

并为您创建一个不错的感谢模板contact-thank-you.html

资源:

php.net:标头()

于 2013-04-04T00:53:18.743 回答
4

代替:

echo "Thank you, you message has been sent!";

和:

header('Location: contact-thank-you.html');
exit;

参考

于 2013-04-04T00:53:23.173 回答
0

header('位置:thank-you.php');

或者你可以回声按摩(同一个地方的ajax消息)

if(@mail($address, $e_subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
     {
    echo "<p class='ajax_success'>Thanks for Contact Us.</p>";
     }
     else
     {
     echo "<p class='ajax_failure'>Sorry, Try again Later.</p>";
     }

在这里ajax验证;

jQuery.noConflict();

jQuery(document).ready(function ($) {
    //Main Contact Form...
    jQuery("#frmcontact").validate(
    { 
        //Onblur Validation...
        onfocusout: function(element)
        {   
            $(element).valid();
        },         
        rules:
        { 
          txtname:
          {
            required: true,
            minlength: 5
          },
          txtemail:
          {
            required: true,
            email: true
          },          
         txtphone:
          {
            required: true,
            minlength: 5
          },
         txtenquiry:
          {
            required: true,
            minlength: 10
          }       
        }
    });
    //Ajax Submit...
    $('#frmcontact').submit(function () {
    if($('#txtname').is('.valid') && $('#txtemail').is('.valid') && $('#txtphone').is('.valid') && $('#txtenquiry').is('.valid')) {

        var action = $(this).attr('action');

        $("#ajax_message").slideUp(750, function () {
            $('#ajax_message').hide();

            $.post(action, {
                name: $('#txtname').val(),
                email: $('#txtemail').val(),
                phone: $('#txtphone').val(),                
                comment: $('#txtenquiry').val()
            }, function (data) {
                document.getElementById('ajax_message').innerHTML = data;
                $('#ajax_message').slideDown('slow');
                if (data.match('success') != null) $('#frmcontact').slideUp('slow');
            });
        });
      }
      return false;     
    });

and lucks very good
于 2013-04-04T01:29:41.497 回答
0
header('Location: contact-thank-you.html');

这应该是您正在寻找的答案(:

你可以参考这里:http ://www.cyberciti.biz/faq/php-redirect/

于 2013-04-04T00:57:38.053 回答
0

如果您想从 html 页面重定向到另一个页面,例如 php 页面,那么只需编写此代码,它将为您工作

<?php  
  header( 'Location: http://www.yoursite.com/new_page.html' ) ; 
   //or 
  header( 'Location: nextpage.php' ) ; 
 ?>
于 2014-09-05T23:58:46.370 回答