-2

お問い合わせフォームのページで実行される PHP フォームがあります。うまく機能していますが、現在のところ、名前と電子メールが入力されていることを確認するだけです。私もメッセージをチェックしようとしていますが、私の試みはphpの後にページが読み込まれないようにするだけです. ここに私が持っているものがあります:

<?php 
 $to = "me@gmail.com" ; 
 $from = $_REQUEST['Email'] ; 
 $name = $_REQUEST['Name'] ; 
 $headers = "From: $from"; 
 $subject = "Web Contact Data";
 $startmonth = $_REQUEST['StartMonth'];
 $startyear = $_REQUEST['StartYear'];
 $endmonth = $_REQUEST['EndMonth'];
 $endyear = $_REQUEST['EndYear'];
 $message = $_REQUEST['Message'];

 $fields = array(); 
 $fields{"Name"} = "Name"; 
 $fields{"Email"} = "Email"; 
 $fields{"Phone"} = "Phone"; 

 $selectedProjects  = 'None';
if(isset($_POST['projects']) && is_array($_POST['projects']) && count($_POST['projects']) > 0){
    $selectedProjects = implode(', ', $_POST['projects']);
}
 $selectedSkills  = 'None';
if(isset($_POST['skills']) && is_array($_POST['skills']) && count($_POST['skills']) > 0){
    $selectedSkills = implode(', ', $_POST['skills']);
}
$selectedNoRush  = 'None';
if(isset($_POST['norush']) && is_array($_POST['norush']) && count($_POST['norush']) > 0){
    $NoRush= implode(', ', $_POST['norush']);
}
$selectedWhenReady  = 'None';
if(isset($_POST['whenready']) && is_array($_POST['whenready']) && count($_POST['whenready']) > 0){
    $WhenReady= implode(', ', $_POST['whenready']);
}
$selectedBudget  = 'None';
if(isset($_POST['budget']) && is_array($_POST['budget']) && count($_POST['budget']) > 0){
    $selectedBudget= implode(', ', $_POST['budget']);
} 

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);}
$body .= "\n" . 'Selected Projects: ' . $selectedProjects . "\n";
$body .= 'Selected Skills: ' . $selectedSkills . "\n\n";
$body .= 'Start Date: ' . $startmonth . " " . $startyear . " " . $NoRush . "\n";
$body .= 'End Date: ' . $endmonth . " " . $endyear . " " . $WhenReady . "\n";
$body .= 'Budget: ' . $selectedBudget . "\n\n";
$body .= 'Message:' . $message . "\n";



 $headers2 = "From: me@gmail.com"; 
 $subject2 = "Thank you for contacting us"; 
 $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";

 if($from == '') {print "You have not entered an email, please go back and try again";} 
 else { 
 if($name == '') {print "You have not entered a name, please go back and try again";} 
 else {
 $send = mail($to, $subject, $body, $headers); 
 $send2 = mail($from, $subject2, $autoreply, $headers2); 
 if($send) 
 {print "Thank you. Your request has been successfully submitted.";} 
 else 
 {print "We encountered an error sending your mail, please check your details are correct or email us at hello@lyonempire.co.uk"; } 
 }
}
 ?>

したがって、上記はすべて正常に機能しますが、名前/メールチェックの後に次のコードを追加すると、壊れます:

if($message == '') {print "You have not entered a message, please go back and try again";} 
 else {

私は何を間違っていますか?

ありがとう!MC

4

2 に答える 2

1
if($name == '')
{
    print "You have not entered a name, please go back and try again";
}
else if($message == '') {
    // do what ever you want
} 
else {
    $send = mail($to, $subject, $body, $headers); 
    $send2 = mail($from, $subject2, $autoreply, $headers2); 

....残りはここに入る

于 2013-06-26T13:19:34.677 に答える
0

あなたが示したコードからはわかりませんが、elseステートメントで中括弧を閉じましたか?

if($message == '') {print "You have not entered a message, please go back and try again";} 
else {} <----
于 2013-06-26T13:13:34.077 に答える