2016-12-20 4 views
2

フォームを送信すると、「No arguments Provide!」というステートメントが表示されます。しかし、私は同じ正確なフォームを実行する2番目のウェブサイトを持っており、それは完全に動作します。 PHPファイルはBootstrap Agencyテンプレートのものです。ここではすべてのヘルプは大幅にappriciatedされます連絡先フォームを送信する際に、「提供されている引数がありません」

<?php 
// Check for empty fields 
if(empty($_POST['name'])  || 
    empty($_POST['email'])  || 
    empty($_POST['phone'])  || 
    empty($_POST['message']) || 
    !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) 
{ 
echo "No arguments Provided!"; 
return false; 
} 

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$phone = $_POST['phone']; 
$message = $_POST['message']; 

// Create the email and send the message 
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to. 
$email_subject = "Website Contact Form: $name"; 
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message"; 
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected] 
$headers .= "Reply-To: $email_address";  
mail($to,$email_subject,$email_body,$headers); 
return true;   
?> 

コード

HTML

<div class="span9"> 

     <form id="contact-form" class="contact-form" action="contact.php"> 
      <p class="contact-name"> 
       <input id="name" type="text" placeholder="Full Name" value="" name="name" /> 
      </p> 

      <p class="contact-email"> 
       <input id="email" type="text" placeholder="Email Address" value="" name="email" /> 
      </p> 

      <p class="contact-phone"> 
       <input id="phone" type="text" placeholder="Phone Number" value="" name="phone" /> 
      </p> 
      <p class="contact-message"> 
       <textarea id="message" placeholder="Your Message" name="message" rows="15" cols="40"></textarea> 
      </p> 
      <p class="contact-submit"> 
       <li><input type="submit" value="Send Message" class="special" /></li> 
     <li><input type="reset" value="Reset" /></li> 
      </p> 

      <div id="response"> 

      </div> 
     </form> 

PHPです。

+1

デフォルトの方法:ここではコードです。 – jeroen

+2

'if(empty($ _ POST ['name'])){echo" empty name ";}のように、' if'ステートメントを複数の原子チェックに分割することで、エラーメッセージの正確な原因を特定できます。偽を返します。 } elseif(空($ _ POST ['email'])){echo "empty email";偽を返します。 } 'など。 –

+0

ところで、@ jeroenコメントに関しては、$ _REQUEST ['name']'を使ってGETメソッドとPOSTメソッドの両方をサポートすることができます。 –

答えて

0

あなたのフォームにmethod="post"がありません。

<form id="contact-form" class="contact-form" action="contact.php" method="post"> 
+0

ああ、大丈夫です。私はそれを試してみましょう。ありがとうございます –

+0

これは私が得るものです... 構文解析エラー:予期しない ';' /home/username/public_html/contact.php 9行目 –

0

フォームを送信するときのデフォルトの方法はGETです。

だから、あなたが必要とする:

<form method='post' id="contact-form" class="contact-form" action="contact.php"> 
+1

ああ、そうです。ありがとうございました –

1

ファイルの周りを掘りした後、私はこの作品1であると考えています。フォームで送信がGETである

<?php 
// Check for empty fields 
if(empty($_POST['name'])  || 
    empty($_POST['email'])  || 
    empty($_POST['subject'])  || 
    empty($_POST['message']))  
    /* 
    !filter_var($_['email'],FILTER_VALIDATE_EMAIL)) 
    { 
    echo "No arguments Provided!"; 
    return false; 
    } 
    */ 

    if(empty($_POST['name'])) { 
    echo "Please enter your name."; return false; 
    } 
    elseif(empty($_POST['email'])) { 
     echo "Please enter your email."; return false; 
     } 

    if(empty($_POST['message'])) { 
    echo "Please enter your message."; return false; 
    } 
    elseif(empty($_POST['subject'])) { 
    echo "Statement if there is an error"; return false; 
    } 


$name = $_POST['name']; 
$email_address = $_POST['email']; 
$subject = $_POST['subject']; 
$message = $_POST['message']; 

// Create the email and send the message 
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to. 
$email_subject = "Website Contact Form: $subject"; 
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nMessage:\n$message"; 
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected] 
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers); 
return true;    
?> 
関連する問題