我有一個帶有兩個單選按鈕的聯繫表單。但我需要根據所選的單選按鈕向客戶端顯示消息。 我會盡力解釋一下: 如果客戶端選擇YES單選按鈕並按提交,它會顯示一條消息「太棒了!我在那裏見你!」我會收到一封帶有選擇選項的電子郵件。與NO單選按鈕相同,但它會顯示「C'mon ...」作爲消息。(PHP)HTML格式的不同值的不同值。這是可能的?
這裏是PHP的我:
<?php
if(isset($_POST['enviar'])) {
$remetente = "[email protected]";
$destinatario = "[email protected]";
$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/>';
}
PS:這是我第一次問的問題#1 .. 。希望你們明白我的苦衷
編輯: 我這樣做:
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>';
}
不工作。實際上,當用戶選擇「否」單選按鈕時,他會收到正確的消息,但是當他選擇「是」單選按鈕時,他會收到錯誤消息(錯誤消息),但我通常會收到表單電子郵件...
編輯2 好的!有用! 這裏是我做的事:
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>";
}
我真的不知道,如果它的編碼正確的,但它的工作...
你是什麼意思它不工作?上面的代碼會引發一個語法錯誤。如果你先解決這個問題會發生什麼? – madflow
在Dreamweaver中輸入時沒有sintax錯誤。 –
該代碼已被編輯/修正在此期間;) – madflow