2017-10-07 4 views
0

「POSTできません/send_form_email.php」というエラーが表示され、その理由がわかりません。ファイルは同じディレクトリにあります。これらは、サイト上の唯一の2つのHTMLファイルまたはPHPファイルです。ここで"POST/send_form_email.phpエラー"の連絡フォームで

<form id="contactform" action="send_form_email.php" method="post"> 
      <div class="form-group"> 
       <label for="firstname">First Name</label> 
       <input type="text" class="form-control placeholder="First Name" required> 
      </div> 

      <div class="form-group"> 
       <label for="lastname">Last Name</label> 
       <input type="text" class="form-control" placeholder="Last Name" required> 
      </div> 

      <div class="form-group"> 
       <label for="email">Email</label> 
       <input type="text" class="form-control" placeholder="Email" required> 
      </div> 

      <div class="form-group"> 
       <label for="subject">Phone</label> 
       <input type="text" class="form-control" placeholder="Phone" required> 
      </div> 

      <div class="form-group"> 
       <label for="message">Message</label> 
       <textarea id="message" rows="3" class="form-control"></textarea> 
      </div> 

     </div> 

     <div class="modal-footer"> 
      <button class="btn btn-secondary" data-dismiss="modal">Cancel</button> 
      <button name="submit" type="submit" class="btn btn-primary" id="contact-submit">Submit</button> 
     </div> 
     </form> 

は、それがリンクしているPHPファイルです。私はファイル名をダブルチェックしました。変更を確実にするためにキャッシュをクリアしました。

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

    // Sent where the email goes here 
    $email_to = "[email protected]"; 
    $email_subject = "Message from Patient"; 
     function died($error) { 
     // 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['firstname']) || 
     !isset($_POST['lastname']) || 
     !isset($_POST['email']) || 
     !isset($_POST['phone']) || 
     !isset($_POST['message'])) { 
     died('We are sorry, but there appears to be a problem with the form you submitted.'); 
    } 



    $firstname = $_POST['firstname']; // required 
    $lastname = $_POST['lastname']; // required 
    $email = $_POST['email']; // required 
    $phone = $_POST['telephone']; // not 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($comments) < 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.\n\n"; 


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



    $email_message .= "First Name: ".clean_string($firstname)."\n"; 
    $email_message .= "Last Name: ".clean_string($lastname)."\n"; 
    $email_message .= "Email: ".clean_string($email)."\n"; 
    $email_message .= "Telephone: ".clean_string($phone)."\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); 
?> 

<!-- include your own success html here --> 

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

<?php 

} 
+0

エラー全体を投稿できますか?どのウェブサーバーを使用していますか?何がエラーを投げる? – OptimusCrime

+0

localhostとノードサーバー。 –

+0

エラーがあれば、ブラウザから直接send_form_email.phpにアクセスできますか? – BlackBurn027

答えて

0

あなたのPHPコードが実行されることは決してありません、$ _POST [ 'メール']は存在しません。実際にはあなたのフォームには絶対に 'name ='属性はありません。これは、$ _POST配列のフォームから何かを取りたい場合には不可欠です。

など。

<input type="email" name='email' class="form-control" placeholder="Email" required> 

$_POST['email'] will now (when submitted...) hold the e-mail address. 

は注意してください、それが自動的に意志タイプ=「メール」(ブラウザの種類をサポートしている場合、それ以外の場合は、テキストに戻ります)チェック:電子メールのような入力要素のために、あなたは名前=「メール」を指定したいです電子メールアドレスが有効な 'パターン'の場合電子メールアドレスのように見える文字列以外の電子メールアドレスを制限する必要がある場合は、pattern属性を使用することができます。正規表現を指定して、有効な値が一致する必要があります。

(ISSET($ _ POST [「提出」])){あなたが$ _POST配列に/ハンドル値を取得することができ、あなたのコードの残りの部分}

場合、フォームがで提出されたのであれば、私はあなたの最初のチェックをお勧めしたいです
0
<form id="contactform" action="send_form_email.php" method="POST"> 
      <div class="form-group"> 
       <label for="firstname">First Name</label> 
       <input type="text" name="firstname" class="form-control placeholder="First Name" required> 
      </div> 

      <div class="form-group"> 
       <label for="lastname">Last Name</label> 
       <input type="text" name="lastname" class="form-control" placeholder="Last Name" required> 
      </div> 

      <div class="form-group"> 
       <label for="email">Email</label> 
       <input type="text" name="email" class="form-control" placeholder="Email" required> 
      </div> 

      <div class="form-group"> 
       <label for="subject">Ph`enter code here`one</label> 
       <input type="text" name="telephone" class="form-control" placeholder="Phone" required> 
      </div> 

      <div class="form-group"> 
       <label for="message">Message</label> 
       <textarea id="message" name="message" rows="3" class="form-control"></textarea> 
      </div> 

     </div> 

     <div class="modal-footer"> 
      <button class="btn btn-secondary" data-dismiss="modal">Cancel</button> 
      <button name="submit" type="submit" class="btn btn-primary" id="contact-submit">Submit</button> 
     </div> 
     </form> 
+0

私たちが名前で認識したデータを投稿するたびに、このメッセージを使用します。 – saurabh

関連する問題