我正在尝试制作一个表格,询问人们是否参加活动。我搜索了多个主题和论坛。我也使用谷歌并阅读了一些教程,我无法将正确答案与我需要的内容相关联。我试图弄清楚如何发送电子邮件与基于所选单选按钮的消息。如果可以,请你帮助我。非常感谢。
<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="answer" 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="answer" 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消息。这可能吗?
答案 0 :(得分:1)
您需要PHP中的条件,但请注意,在HTML中,“true”和“false”将作为字符串而不是布尔值发送,因此都是真实的,但您可以检查实际的字符串。
$answer = $_REQUEST['answer'] ;
追加/修改/编写您的电子邮件正文后的任何地方,例如
if ($answer=='true') {
$body='Yay you\'re coming';
}else{
$body='Ah screw you then';
}
答案 1 :(得分:0)
这是您需要的绝对基础。只需根据发布的答案交换变量。
if($_POST['answer'] == "true")
{
// user is coming
}
else
{
// user is not coming
}