2016-12-09 15 views
0

毎日送信フォームから空メールを受信して​​います。毎日送信フォームから空メールを毎日受信

フォームコード:

     <div class="form"> 
          <h4 class="h-light text-center">Submit a Query</h4> 

          <form class="form-horizontal" action="sendemail.php" method="post" id="contact_form"> 

            <!-- Text input--> 

            <div class="form-group"> 
             <label class="col-sm-2 control-label">Name</label> 
             <div class="col-sm-10 inputGroupContainer"> 
             <div class="input-group"> 
             <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span> 
             <input name="name" placeholder="Name" class="form-control input-text" type="text" required> 
             </div> 
             </div> 
            </div> 


            <!-- Text input--> 
              <div class="form-group"> 
             <label class="col-sm-2 control-label">E-Mail</label> 
             <div class="col-sm-10 inputGroupContainer"> 
             <div class="input-group"> 
              <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span> 
             <input name="email" placeholder="E-Mail Address" class="form-control input-text" type="email" required> 
             </div> 
             </div> 
            </div> 


            <!-- Text input--> 

            <div class="form-group"> 
             <label class="col-sm-2 control-label">Phone #</label> 
             <div class="col-sm-10 inputGroupContainer"> 
             <div class="input-group"> 
              <span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span> 
             <input name="phone" placeholder="(123)456-7890" class="form-control input-text" type="text" required> 
             </div> 
             </div> 
            </div> 


            <!-- Text area --> 

            <div class="form-group"> 
             <label class="col-sm-2 control-label">Message</label> 
             <div class="col-sm-10 inputGroupContainer"> 
             <div class="input-group"> 
              <span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span> 
               <textarea class="form-control input-text text-area" name="message" placeholder="Enter your massage for us here. We will get back to you." required></textarea> 
             </div> 
             </div> 
            </div> 


            <div class="form-group"> 
             <label class="col-sm-2 control-label"><img src="media/home/captcha.png"></label> 
             <div class="col-sm-10"> 
              <div class="input-group"> 
               <div class="g-recaptcha" data-sitekey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></div> 
              </div> 
             </div> 
            </div> 


            <!-- Success message --> 
            <div class="alert alert-success" role="alert" id="success_message">Success <i class="glyphicon glyphicon-thumbs-up"></i> Thanks for contacting us, we will get back to you shortly.</div> 

            <!-- Button --> 
            <div class="form-group"> 
             <label class="col-sm-4 control-label"></label> 
             <div class="col-sm-8"> 
             <button type="submit" class="input-btn" >Send <span class="glyphicon glyphicon-send"></span></button> 
             </div> 
            </div> 

           </form> 

sendemail.phpコード:

<?php 

    /* These are the variable that tell the subject of the email and where the email will be sent.*/ 

    $emailSubject = 'New query !'; 
    $mailto = '[email protected]'; 

    /* These will gather what the user has typed into the field. */ 

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


    /* This takes the information and lines it up the way you want it to be sent in the email. */ 

    $body = <<<EOD 
    <br><hr><br> 
    Name: $name <br> 
    Email Address: $email <br> 
    Phone Number: $phone <br> 
    Message: $message<br> 

    EOD; 

    $headers = "From:domain.in<[email protected]>\r\n"; // This takes the email and displays it as who this email is from. 
    $headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text. 
    //$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send. 

    if(mail($mailto, $emailSubject, $body, $headers)) 
      { 
        echo "Your query has been submitted successfully. "; 
        echo '<a href="index.html">Go Back</a>'; 
      } 
     else 
     { 
      echo "Failure"; 
     } 
    ?> 

私は何が起こっているか見当がつかない、コードは大丈夫のようですが、それでも私は、空メールを受け付けておりますフィールド名を持つように... 名のみ: Eメールアドレス: 電話番号: メッセージ:

情報は記入されていません。

ありがとうございます。

+0

電子メールを送信する前にフォームが記入されていることを確認するために、いくつかの検証コードを追加してみませんか? –

+0

どうすればいいですか?私は検証のためにブートストラップに必要なタグを使用しています。 –

+0

まだ空メールを受信して​​います。 –

答えて

0

電子メールを送信する前に、PHP側の入力を検証します。例えば:私はPHPとあまり良くないです

$valid = true; 

$name = $_POST['name']; 
if(empty($name)) 
{ 
    echo('Please enter your name'); 
    $valid = false; 
} 

// Repeat for other fields 

if($valid) 
{ 
    // Send the email 
} 
+0

私は昨日送ったものを試しましたが、コードは動作していません –

+0

何が問題なのですか?それは何を出力していますか? –

0

、それが正しいなら、私に知らせてください..

<?php 

    /* These are the variable that tell the subject of the email and where the email will be sent.*/ 

    $emailSubject = 'New query!'; 
    $mailto = '[email protected]'; 

    /* These will gather what the user has typed into the fieled. */ 

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


    /* This takes the information and lines it up the way you want it to be sent in the email. */ 

    $body = <<<EOD 
    <br><hr><br> 
    Name: $name <br> 
    Email Address: $email <br> 
    Phone Number: $phone <br> 
    Message: $message<br> 

    EOD; 

    $headers = "From:domain.in<[email protected]>\r\n"; // This takes the email and displays it as who this email is from. 
    $headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text. 
    //$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send. 


    $valid = true; 

    $name = $_POST['name']; 
    if(empty($name)) 
    { 
     echo('Please enter your name'); 
     $valid = false; 
    } 

    $email = $_POST['email']; 
    if(empty($email)) 
    { 
     echo('Please enter your email'); 
     $valid = false; 
    } 

    $phone = $_POST['phone']; 
    if(empty($phone)) 
    { 
     echo('Please enter your Phone number'); 
     $valid = false; 
    } 

    $message = $_POST['message']; 
    if(empty($message)) 
    { 
     echo('Please enter your message'); 
     $valid = false; 
    } 


    if($valid) 
    { 
     if(mail($mailto, $emailSubject, $body, $headers)) 
      { 
        echo "Your query has been submitted successfully. "; 
        echo '<a href="index.html">Go Back</a>'; 
      } 

    } 
    else 
     { 
      echo "Failure"; 
     } 

    i 
    ?> 
+0

はい、構文エラーの原因となる最後に「i」が付いていることを除いて動作します。また、すべてのecho文に改行を追加したい場合は、次のように出力されます: "あなたの名前を入力してください。電話番号を入力してください。あなたのメッセージを入力してください。" –

0

は今働いれるべきいただきありがとうございますか!

$valid = true; 

$name = $_POST['name']; 
if(empty($name)) 
{ 
    echo('Please enter your name'); 
    $valid = false; 
} 
<br/> 

$email = $_POST['email']; 
if(empty($email)) 
{ 
    echo('Please enter your email'); 
    $valid = false; 
} 
<br/> 

$phone = $_POST['phone']; 
if(empty($phone)) 
{ 
    echo('Please enter your Phone number'); 
    $valid = false; 
} 
<br/> 

$message = $_POST['message']; 
if(empty($message)) 
{ 
    echo('Please enter your message'); 
    $valid = false; 
} 
<br/> 

if($valid) 
{ 
    if(mail($mailto, $emailSubject, $body, $headers)) 
     { 
       echo "Your query has been submitted successfully. "; 
       echo '<a href="index.html">Go Back</a>'; 
     } 

} 
else 
    { 
     echo "Failure"; 
    } 


?> 
+0

このコードは動作しません。あなたはPHPコードでHTMLを持っています。 –

0

$ _Postが空であるかどうかを確認することは、通常のやり方です。

なぜ、同じ空のメールが毎日あなたに送信されているのか不思議です(通常はボットのようなものです)。あなたのメッセージ本文に次のフィールドを追加して、何が起きているのか知ってください。

このようにして、Webの仕組みを学びます。

$ip = $_SERVER['REMOTE_ADDR']; // for IP address 
$browser = $_SERVER['HTTP_USER_AGENT']; // get browser info 

、あなたは何が起こっているか知っているので、あなたのメッセージ本文に情報の上に追加しますたとえば

+0

このコードを追加した後、私が受け取った空のメールがボットからのものであることをどのように認識しますか? –

+0

それは通常、それがクロム、ウィンドウ、モジラなどの情報を返す通常の人の場合は、依存します。これは調査目的のためであり、空の電子メールの送信を止めるものではありません。最善の方法は、まだ電子メールが送信される前に$ _POSTが空であるかどうかを確認することです。そして、より良いものでさえフロントエンドをチェックすることです。 –

関連する問題