我正在尝试制作一个表格,询问人们是否正在参加活动。我搜索了多个帖子和论坛。我还求助于谷歌,阅读了一些教程,但我无法将正确答案与我需要的内容联系起来。我正试图弄清楚如何根据所选的单选按钮向发送电子邮件。如果可以的话,请帮帮我。非常感谢。
<FORM method="post" name="RSVPform" action="respond.php" target="_blank">
Name(s): <input name="name" size="42" type="text" /><br/><br/>
Will you be attending the event?<br/><br/>
<input checked="checked" name="answerswer" type="radio" value="true" /> Yes, I(we) will attend.<br/><br/>
If yes, how many will be attending? <input name="number" size="25" type="text" /><br/><br/>
<input name="answerswer" type="radio" value="false"/>Sadly, we are unable to attend. <br/><br/> <input name="Submit" type="submit" value="Submit" />
</FORM>
这是我一直在尝试使用的php。
<?php
$to = "myemail@email.com";
$name = $_REQUEST['name'] ;
$answer = $_REQUEST['answer'] ;
$subject = "RSVP from: $name";
$number = $_REQUEST['number'] ;
$headers = "RSVP";
$body = "From: $name, 'n'n I(we) will be attending the event. There will be $number of us. 'n'n Thanks for the invite.";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
else
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
?>
我不知道如何根据所选的单选按钮更改$body消息。这可能吗?
您在PHP中需要一个条件,但请注意,在HTML中,"true"answers"false"将作为字符串而非布尔值发送,因此两者都是truthy,但您可以检查实际字符串。
$answer = $_REQUEST['answer'] ;
之后的任何位置附加/修改/写入您的电子邮件正文,例如
if ($answer=='true') {
$body='Yay you''re coming';
}else{
$body='Ah screw you then';
}
以下是您所需要的绝对基础。只需根据发布的答案交换变量即可。
if($_POST['answer'] == "true")
{
// user is coming
}
else
{
// user is not coming
}