douyan1944 2013-11-11 20:14
浏览 150
已采纳

表单提交后无法重定向

I have a form on a HTML page that has form data, and would like to have the user redirected to a new URL page after they have pressed the submit button and it has emailed the information. The form is called with the following button.

<div class="btnp"><input type="submit"  value="Continue to Billing" ></div>

The form then sends the data to my PHP file via post. I do not need a success echo message, I would just like the URL to be redirected to the payment page. Below is the PHP file I have set up. I am trying to submit, send email with form date, and then redirect to a new html url.

<?php
//Retrieve form data. 
//POST
$URL = "http://www.google.com"; 
$fname  = $_POST['fname'];              
$zip = $_POST['zip'];       
$phone = $_POST['phone'];       
$email = $_POST['email'];       

    //recipient - change this to your name and email
    $to = 'sales@mysite.com';   
    //sender
    $from = $fname . ' <' . $email . '>';

    //subject and the html message
    $subject = 'New User: ' . $fname;   
    $message = '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head></head>
    <body>
        <table>
            <tr><td>First Name</td><td>' . $fame . '</td></tr>      
            <tr><td>Zip</td><td>' . $zip . '</td></tr>      
            <tr><td>Telephone</td><td>' . $phone . '</td></tr>  
            <tr><td>Email</td><td>' . $email . '</td></tr>  
        </table>
    </body>
    </html>';

    //send the mail
    $result = sendmail($to, $subject, $message, $from);

    if ($_POST) 
        if ($result) header('Location: '.$URL);
        else echo 'Sorry, unexpected error. Please try again later';

    //Simple mail function with HTML header
    function sendmail($to, $subject, $message, $from) {
    $headers = "MIME-Version: 1.0" . "
";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "
";
    $headers .= 'From: ' . $from . "
";  
    $result = mail($to,$subject,$message,$headers);
    }       
?>    
  • 写回答

2条回答 默认 最新

  • dqz7636 2013-11-11 20:18
    关注

    use the header('Location: $url); snippet that your tried but correct the function to this:

    header('Location: '.$URL);
    

    just make sure the varibale $URL is defined.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿