2017-07-10 4 views
0

私はここで前もって話し合うつもりです。私は実際にPHPを知らないが、私が構築している私のウェブサイトのための簡単な電子メールフォームを作るためにそれを使用したい。私は思っていたことをまとめましたが、提出をクリックするとエラーが表示されます。お問い合わせフォームbootstrap php

誰かが私にそれを動作させるために間違っていることを教えてもらえますか?

ここでは、コード(私はオーバーコードを掲載場合は申し訳ありませんが、私は問題があるわずかな手掛かりを持っていない)です:

Contact.html:

<h1 class="cover-heading">Contact Me</h1> 
     <div class="form-area"> 
      <form role="form" method="post" action="Contact.php"> 
      <br style="clear:both"> 

      <div class="form-group"> 
       <input type="text" class="form-control" id="name" name="name" placeholder="Name" 
       required> 
      </div> 
      <div class="form-group"> 
       <input type="text" class="form-control" id="email" name="email" placeholder="Email" 
       required> 
      </div> 
      <div class="form-group"> 
       <input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number" 
       required> 
      </div> 
      <div class="form-group"> 
       <input type="text" class="form-control" id="subject" name="subject" placeholder="Subject" 
       required> 
      </div> 
      <div class="form-group"> 
       <textarea class="form-control" type="textarea" name="message" id="message" placeholder="Message" 
       maxlength="1337" rows="7"></textarea> 
       <span class="help-block"><p id="characterLeft" class="help-block ">You have reached the limit</p></span> 
      </div> 

      <button type="submit" id="submit" name="submit" class="btn btn-lg btn-secondary ">Submit Form</button> 

      </form> 
     </div> 

Contact.php:

はここで
<?php 
if(isset($_POST['email'])) { 

// EDIT THE 2 LINES BELOW AS REQUIRED 
$email_to = "[email protected]"; 
$email_subject = "ChristopherBare.com Contact form"; 

function died($error) { 
    // your error code can go here 
    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(); 
} 


// validation expected data exists 
if(!isset($_POST['name']) || 
    !isset($_POST['subject']) || 
    !isset($_POST['email']) || 
    !isset($_POST['mobile']) || 
    !isset($_POST['message'])) { 
    died('We are sorry, but there appears to be a problem with the form you submitted.'); 
} 



$name = $_POST['name']; // required 
$email = $_POST['email']; // required 
$mobile = $_POST['mobile']; // not required 
$subject = $_POST['subject']; //required 
$message = $_POST['message']; // required 

$error_message = ""; 
$email_exp = '/^[A-Za-z0-9._%-][email protected][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,$first_name)) { 
$error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
} 

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

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

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

$email_message = "Form details below.\n\n"; 


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



$email_message .= "Name: ".clean_string($name)."\n"; 
$email_message .= "Email: ".clean_string($email)."\n"; 
$email_message .= "Mobile: ".clean_string($mobile)."\n"; 
$email_message .= "Subject: ".clean_string($subject)."\n"; 
$email_message .= "Comments: ".clean_string($message)."\n"; 

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





<?php 

} 
?> 

エラーです:

"; echo $error." 

"; echo "Please go back and fix these errors. 

"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['subject']) || !isset($_POST['email']) || !isset($_POST['mobile']) || !isset($_POST['message'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email = $_POST['email']; // required $mobile = $_POST['mobile']; // not required $subject = $_POST['subject']; //required $message = $_POST['message']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-][email protected][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. 
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid. 
'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid. 
'; } if(strlen($message) < 2) { $error_message .= 'The message you entered does not appear to be valid. 
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Mobile: ".clean_string($mobile)."\n"; $email_message .= "Subject: ".clean_string($subject)."\n"; $email_message .= "Comments: ".clean_string($message)."\n"; // create email headers $headers = 'From: '.$email."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> 
+1

あなたのエラーは何ですか? –

+0

[送信]ボタンをクリックすると、フォームに何もないという検証エラーが返されます。 –

+0

どの検証? –

答えて

1

あなたのエラーに基づいて、あなたのシステムにPHPがインストールされていないように見えます。

あなたがここにPHPをダウンロードすることができます:http://php.net/downloads.php

は、Windows OSを使用している場合、私はあなたが簡単に使用するためにXAMPPをインストールお勧めします。 xamppはこちらからダウンロードできます:https://www.apachefriends.org/index.html

+0

私はaptでイ​​ンストールしてapache2.serviceのものを再起動しました。まだ動作していません。私はまた私のドメインのftpに入れようとしましたが、それは500の内部サーバエラーを返しました。私はちょうど完全に何かを逃しているように感じている –

+0

あなたのPHPに正常にインストールされているかどうかを確認するブラウザでlocalhostを開こうとしたことがありますか? –

+0

私が得るのは、apache2のデフォルトページです。私は現在、Atomで自分のサイトを編集していて、ブラウザでファイルを表示しています。私はPHPがインストールされているかどうかを確認する方法を知らない –

関連する問題