我在一个包含表单数据的 HTML 页面上有一个表单,并且希望用户在按下提交按钮并通过电子邮件发送信息后将其重定向到新的 URL 页面。使用以下按钮调用表单。
<div class="btnp"><input type="submit" value="Continue to Billing" ></div>
然后表单通过 post 将数据发送到我的 PHP 文件。我不需要成功回显消息,我只想将 URL 重定向到付款页面。下面是我设置的 PHP 文件。我正在尝试提交、发送带有表单日期的电子邮件,然后重定向到新的 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);
}
?>