dongra1984 2013-12-19 10:49
浏览 51

html和php联系表单麻烦

Can somebody please tell me what is wrong with my code. I cant figure out what the error is.

contact form

<form action="mail.php" method="POST">
                <p>Name</p> <input type="text" name="name">
                <p>Email</p> <input type="text" name="email">
                <p>Phone</p> <input type="text" name="telephone">

                <p>Request Phone Call:</p>
                Yes:<input type="checkbox" value="Yes" name="call">
                No:<input type="checkbox" value="No" name="call"><br />

                <p>Priority</p>
                <select name="priority" size="1">
                    <option value="Low">Low</option>
                    <option value="Normal">Normal</option>
                    <option value="High">High</option>
                    <option value="Emergency">Emergency</option>
                </select>
                <br />

                <p>Type</p>
                <select name="type" size="1">
                    <option value="update">Website Update</option>
                    <option value="change">Information Change</option>
                    <option value="addition">Information Addition</option>
                    <option value="new">General Enquiries</option>
                </select>
                <br />

                <p>Message</p><textarea name="message" rows="10" cols="40"></textarea><br />
                <input type="submit" value="Send" class="button"/><input type="reset" value="Clear" class="button"/>
            </form>

mail.php

<?php 

if(isset($_POST['email'])) { 

$email_to = "myemail@sky.com"; 
$email_subject = "Tip Top Music"; 

function died($error) { 

    // Error codes
    echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
    echo "These errors appear below.<br /><br />"; 
    echo $error."<br /><br />";  
    echo "Please go back and fix these errors.<br /><br />"; 
    die(); 

} 

// Required fields
if(!isset($_POST['name']) ||  
    !isset($_POST['email']) ||   
    !isset($_POST['message'])) { 

    died('Required Fields are not complete');        
} 

$name = $_POST['name']; // required 
$email_from = $_POST['email']; // required 
$telephone = $_POST['telephone']; // not required 
if(!isset($_POST['call'])) {
 $call = "No"; // if checkbox was left unchecked. Default is No
}
else {
    $call = ($_POST['call'])
}
$priority = $_POST['priority'];  // Will already have default value
$type = $_POST['type'];  // Will already have default value
$message = $_POST['message']; // required 
$error_message = ""; 

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 

if(!preg_match($email_exp,$email_from)) { 
  $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
} 

$string_exp = "/^[A-Za-z .'-]+$/"; 

if(!preg_match($string_exp,$name)) { 
    $error_message .= 'The Name you entered does not appear to be valid.<br />'; 
}

if(strlen($message) < 2) { 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 
} 

if(strlen($error_message) > 0) { 
    died($error_message); 
} 

$email_message = "Form details below.

"; 

function clean_string($string) { 
    $bad = array("content-type","bcc:","to:","cc:","href"); 
    return str_replace($bad,"",$string); 
} 

$email_message .= "Name: ".clean_string($name)."
"; 
$email_message .= "Email: ".clean_string($email_from)."
"; 
$email_message .= "Request Callback: ".($call)."
";
$email_message .= "Telephone: ".clean_string($telephone)."
"; 
$email_message .= "Priority: ".($priority)."
";
$email_message .= "Type: ".($type)."
";
$email_message .= "Message: ".clean_string($message)."
"; 

// create email headers 
$headers = 'From: '.$email_from."
". 
'Reply-To: '.$email_from."
" . 
'X-Mailer: PHP/' . phpversion(); 
@mail($email_to, $email_subject, $email_message, $headers);   

?> 

<!-- Message success --> 

Thank you for contacting us. We will be in touch with you very soon. 

<?php 


} 

?>

I get undefined index call pointing to $call = "No"; line. HOWEVER the script should not even run at all because I posted a blank form?? When I echo the input fields they are blank but they if put IF statements in to check if they are set (isset) it goes into the statement as if they have been set? Should I be using something other than isset to check for empty inputs? This usually works so im confused as to why its not now?

  • 写回答

2条回答 默认 最新

  • duanji5569 2013-12-19 10:54
    关注

    Missing semicolon on $_POST['call']

    if(!isset($_POST['call'])) {
     $call = "No"; // if checkbox was left unchecked. Default is No
    }
    else {
        $call = $_POST['call']; // Missing semicolon here
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀