表单提交后无法重定向 [英] Cannot redirect after form submission
问题描述
我在一个含有表单数据的HTML页面上有一个表单,并希望在用户按下提交按钮并通过电子邮件发送信息后,将用户重定向到新的URL页面。
< div class =btnp>< input type =submit value =继续结算>< / div>
表单然后通过post发送数据到我的PHP文件。我不需要成功的回复消息,我只想将网址重定向到付款页面。以下是我设置的PHP文件。我正在尝试提交,发送带有表单日期的电子邮件,然后重定向到一个新的html网址。
<?php
//检索表单数据。
// POST
$ URL =http://www.google.com;
$ fname = $ _POST ['fname'];
$ zip = $ _POST ['zip'];
$ phone = $ _POST ['phone'];
$ email = $ _POST ['email'];
//收件人 - 将其更改为您的姓名和电子邮件
$ to ='sales@mysite.com';
//发件人
$从= $ fname。 '<'。 $电子邮件。 >;
//主题和html消息
$ subject ='新用户:'。 $ 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>名字< / td>< td>'。 $名声。 < / TD>< / TR>
< tr>< td> Zip< / td>< td>'。 $ zip。 < / TD>< / TR>
< tr>< td>电话< / td>< td>'。 $手机。 < / TD>< / TR>
< tr>< td>电子邮件< / td>< td>'。 $电子邮件。 < / TD>< / TR>
< / table>
< / body>
< / html>';
//发送邮件
$ result = sendmail($ to,$ subject,$ message,$ from); ($ _POST)
if($ result)header('Location:'。$ URL);
if
else echo'抱歉,意外的错误。请稍后再试';
//带HTML头的简单邮件函数
函数sendmail($ to,$ subject,$ message,$ from){
$ headers =MIME-Version:1.0 。 \r\\\
;
$ headers。=Content-type:text / html; charset = iso-8859-1。 \r\\\
;
$ headers。='From:'。 $从。 \r\\\
;
$ result = mail($ to,$ subject,$ message,$ headers);
}
?>
使用
header(位置:$ url);
snippet表示你试过但正确的函数: 'Location:'。$ URL);
只要确保varibale $ URL
是定义。
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" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
}
?>
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.
这篇关于表单提交后无法重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!