(PHP)html格式中不同值的不同值
作者:互联网
我有一个带两个单选按钮的联系表格.但我需要根据所选的单选按钮向客户端显示消息.
我会尝试更好地解释:
如果客户选择YES单选按钮并按提交,则会显示一条消息“太棒了!我看到你了!”我将收到一封包含所选选项的电子邮件.与NO单选按钮相同,但它会显示为“来电……”作为消息.
这是我的PHP:
<?php
if(isset($_POST['enviar'])) {
$remetente = "email@domain.com";
$destinatario = "email@domain.com";
$assunto = "Subject";
$data = date("d/m/y");
$hora = date("H:i");
$charset = $_POST['charset'];
$nome = $_POST['nome'];
$email = $_POST['email'];
//This is the radio button value that i want to put conditionals.
$rsvp = $_POST['rsvp'];
$navegador = $_SERVER['HTTP_USER_AGENT'];
$ip = $_SERVER['REMOTE_ADDR'];
$corpo = utf8_decode("Data: ".$data."<br />Hora: ".$hora."<br />Nome: ".$nome."<br />E-mail: ".$email."<br />Ip: ".$ip."<br />Browser: ".$navegador."<br />RSVP: ".$rsvp."\r\n");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=".$charset."\r\n";
$headers .= "Reply-To: ".$remetente."\r\n";
$headers .= "From: ".$remetente."\r\n";
//This is the part that i think it has to be changed.
if(mail($destinatario, $assunto, $corpo, $headers)) {
echo '<meta http-equiv="refresh" content=0;url=message_sended.php/>';
} else {
echo '<meta http-equiv="refresh" content=0;url=error.php/>';
}
} else {
echo '<meta http-equiv="refresh" content=0;url=error.php/>';
}
?>
我试过这个,但是没有用:
if(mail($destinatario, $assunto, $corpo, $headers) ) {
if($rsvp = 'YES'){
echo '<meta http-equiv="refresh" content=0;url=message_sended_YES.php/>';
} else {
echo '<meta http-equiv="refresh" content=0;url=error.php/>';
}
} else {
echo '<meta http-equiv="refresh" content=0;url=error.php/>';
}
if($rsvp = 'NO'){
echo '<meta http-equiv="refresh" content=0;url=message_sended.php_NO/>';
} else {
echo '<meta http-equiv="refresh" content=0;url=error.php/>';
}
} else {
echo '<meta http-equiv="refresh" content=0;url=error.php/>';
}
然后我这样做了:
if(mail($destinatario, $assunto, $corpo, $headers)) {
if($rsvp == 'sim'){
echo '<meta http-equiv="refresh" content=0;url=sim.php>';
}
else
{
echo '<meta http-equiv="refresh" content=0;url=contato_mensagem_erro.php>';
}
}
else
{
echo '<meta http-equiv="refresh" content=0;url=contato_mensagem_erro.php>';
}
if($rsvp == 'nao'){
echo '<meta http-equiv="refresh" content=0;url=nao.php>';
}
else
{
echo '<meta http-equiv="refresh" content=0;url=contato_mensagem_erro.php>';
}
}
else
{
echo '<meta http-equiv="refresh" content=0;url=contato_mensagem_erro.php>';
}
不管用.实际上,当用户选择“否”单选按钮时,他会收到正确的消息,但是当他选择“是”单选按钮时,他会收到错误的消息(错误消息),但我通常会收到表单电子邮件…
编辑
好!有用!
我是这样做的:
if(mail($destinatario, $assunto, $corpo, $headers)) {
if($rsvp == "sim"){
echo
header('Location: sim.php/');
}
else
{
echo "<meta http-equiv='refresh' content=0;url=contato_mensagem_erro.php>";
}
}
else
{
echo "<meta http-equiv='refresh' content=0;url=contato_mensagem_erro.php>";
}
if($rsvp == "nao"){
echo header('Location: nao.php/');
}
else
{
echo "<meta http-equiv='refresh' content=0;url=contato_mensagem_erro.php>";
}
}
else
{
echo "<meta http-equiv='refresh' content=0;url=contato_mensagem_erro.php>";
}
我真的不知道它是否正确编码,但它正在工作……
解决方法:
这些线将导致意想不到的结果:
if($rsvp = 'YES'){
if($rsvp = 'NO'){
此方法只需将$rsvp的值分别设置为“YES”和“NO”.要测试等价,您应该使用比较运算符==:
if($rsvp == 'YES'){
和
if($rsvp == 'NO'){
标签:contact-form,php,if-statement,conditional,message 来源: https://codeday.me/bug/20190903/1795945.html