我使用html制作了一个html,它包含一些单选按钮。我怎么知道选择了哪个按钮?我需要将选定的选项发送到我的电子邮件,但我不太明白它将如何合并到我的PHP脚本中。非常感谢你们!
下面是我的php脚本:
<?php
$to = 'dinefour4@gmail.com';
$subject = 'The subject';
$name = $_POST['name'];
$email = $_POST['email'];
$option = $_POST['place']; <-- is this the way to know the selected button?
$mobile = $_POST['mobile'];
$message = <<<EMAIL
$name
$email
$mobile
EMAIL;
$header = '$email';
if($_POST) {
mail($to, $subject, $message, $header);
}
?>
<div id="signup">
<form action="signup.php" method="POST" onsubmit="return validate()">
<label name = "sutitle"> <font size="7"> sign up here!</font></label> <br/>
<label ><font size="5" >Name:</font>
<input type="text" name="name" required ></label><br />
<label ><font size="5">Mobile:</font>
<input type="text" name="mobile" required></label><br />
<label ><font size="5">Email: </font>
<input type="text" name="email" required></label><br />
<label> <font size="5">Where to meet your Friends?</font><br/>
<input type="radio" name="place" value="revelle" > <font size="5">Revelle </font><br>
<input type="radio" name="place" value="muir"> <font size="5">Muir </font><br>
<input type="radio" name="place" value="warren"> <font size="5">Warren </font><br>
<input type="radio" name="place" value="erc" > <font size="5">ERC </font><br>
<input type="radio" name="place" value="village"> <font size="5">The Village </font><br>
</label>
<input type="submit" value="Submit">
</form>
答案 0 :(得分:1)
<?php
$to = 'dinefour4@gmail.com';
$subject = 'The subject';
$name = $_POST['name'];
$email = $_POST['email'];
$option = ""
if(isset($_POST['place']))
{
$option = $_POST['place'];
}
$mobile = $_POST['mobile'];
$message = <<<EMAIL
$name
$email
$mobile
EMAIL;
$header = '$email';
if($_POST) {
mail($to, $subject, $message, $header);
}
?>
<div id="signup">
<form action="signup.php" method="POST" onsubmit="return validate()">
<label name = "sutitle"> <font size="7"> sign up here!</font></label> <br/>
<label ><font size="5" >Name:</font>
<input type="text" name="name" required ></label><br />
<label ><font size="5">Mobile:</font>
<input type="text" name="mobile" required></label><br />
<label ><font size="5">Email: </font>
<input type="text" name="email" required></label><br />
<label> <font size="5">Where to meet your Friends?</font><br/>
<input type="radio" name="place" value="revelle" > <font size="5">Revelle </font><br>
<input type="radio" name="place" value="muir"> <font size="5">Muir </font><br>
<input type="radio" name="place" value="warren"> <font size="5">Warren </font><br>
<input type="radio" name="place" value="erc" > <font size="5">ERC </font><br>
<input type="radio" name="place" value="village"> <font size="5">The Village </font><br>
</label>
<input type="submit" value="Submit">
如果选中单选按钮,则会在&#39; $选项中设置&#39;变量。否则&#39; $ option&#39;变量将为空。