【发布时间】:2025-11-28 06:00:02
【问题描述】:
我对 PHP 很陌生。
我有一个 HTML 会员表单,当用户单击提交按钮时,它会转到一个 PHP 页面,该页面编译传递的字段,发送一封电子邮件,最后将用户转发到“谢谢”确认 html 页面。
我想在 URL 字符串中包含两个表单字段,这样我就可以在确认页面中致电祝贺加入我们俱乐部的人的姓名。
两个问题
- 如何连接重定向 url 以包含名字和姓氏,例如: new_member_confirmation.html?firstname=$firstname&lastname=$lastname
- 然后我如何“获取”URL 字符串中的名称以显示在确认 html 页面上。例如“感谢 Bill Smith 成为会员”。我没有这样的例子,因为我不知道如何从 url 字符串调用或获取值到 HML 页面中
这是修改后的代码,它不包括每个表单字段变量,但为您提供了 PHP 脚本的要点。
<?php
// Multiple recipients
$to = 'info@abs.com'; // note the comma
// Form http_post_fields
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$subject = 'New Membership';
$cdateTime = date("l jS \of F Y h:i:s A");
// Message
$message = "
<html>
<head>
<title>New Membership</title>
</head>
<strong>From:</strong> \n $firstname \n $lastname <br>
<strong>Email:</strong> \n $email <br>
<strong>Date/Time Submitted:</strong>\n $cdateTime
</font></p>
<body>
</body>
</html>
";
// To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Additional headers
$headers[] = 'To: Club Name <info@domain.com>'; // include a comma for more than one recipiant
$headers[] = 'From: Club Name <info@domain.com>';
// Mail it
mail($to, $subject, $message, implode("\r\n", $headers)) or die("Email was not sent!");
// Here is where the user gets sent to the page below. Id like to append the $firstname $lastname variables into the URL string
header('Location: membership_confirmation.html');
// I thought I could create a URL string variable above like this --
// $urString = "Location: membership_confirmation.html?membername=$firstname \n $lastname";
// and then add it to the last portion of the script like this
// header($urString);
// Unfortunately, that doesn't work after I tried testing it.
?>
【问题讨论】:
标签: javascript php