3

こんにちは、私は以前にこの非常に単純な php 連絡先スクリプトを使用して成功しましたが、フォームを使用して新しい HTML ページに実装しようとすると、送信されません。誰でも明らかなエラーを見ることができますか? どんな助けでも大歓迎です

フォームのhtmlは次のとおりです。

<div id="formContainer">

    <form action="form.php" method="post" id="contactForm"> 
    <fieldset>

    <legend>Your details</legend>    

    <label for="name">Name *</label>
    <input type="text" id="name">

    <label for="email">Email *</label>
    <input type="email" id="email">

    <label for="tel">Telephone</label>
    <input type="tel" id="tel">

    </fieldset>

    <fieldset> 
    <legend>Tutoring</legend>

    <label for="type">Type of lesson</label>
    <select name="type" id="type">
    <option>Individual</option>
    <option>Group</option>
    </select>

    <label for="subject">Subject</label>
    <input name="subject" list="subjects" id="subject">
    <datalist id="subjects">
    <option>English</option>
    <option>Biology</option>
    <option>Geography</option>
    </datalist>

    <label for="level">Your level</label>
    <select name="level" id="level">
    <option>Beginner</option>
    <option>GCSE</option>
    <option>A-Level</option>
    <option>University</option>
    </select>

    <label for="hours">Hours/week</label>
    <input type="number" id="hours">

    <label for="info">Additional Information</label>
    <textarea name="info" id="info" rows="10"               cols="6"></textarea>


    </fieldset>

    <input type="submit" name="submit" value="Send" id="sendButton">

    <input type="hidden" name="submit_check" value="1" />   
    </form>

    </div>

簡単な php スクリプトは次のとおりです。

<?php 

if ($_POST["email"]<>'') { 
    $ToEmail = 'onjegolders@gmail.com'; 
    $EmailSubject = 'Site contact form '; 
    $mailheader = "From: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
    $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
    $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
    $MESSAGE_BODY = "Telephone: ".$_POST["tel"]."<br>";
    $MESSAGE_BODY = "Type: ".$_POST["type"]."<br>";
    $MESSAGE_BODY = "Subject: ".$_POST["subject"]."<br>";
    $MESSAGE_BODY = "Level: ".$_POST["level"]."<br>";
    $MESSAGE_BODY = "Hours required: ".$_POST["hours"]."<br>";
    $MESSAGE_BODY .= "Additional information: ".nl2br($_POST["info"])."<br>"; 
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 

?> 

<html>

    <h3>Thanks for your email</h3>
    <h4>I'll get back to you as soon as possible</h4>
    <a href="index.html"><p>Click here to go back to previous page</p></a>

</html>


<?php 
} else { 
?> 

<html>Sorry, this form didn't work</html>

<?php 
}; 
?>
4

5 に答える 5

3

試してみてください

if ( !empty($_POST["email"]) )

ただし、次を使用してそのページに投稿されているものを確認できます。

echo '<pre>';
var_dump( $_POST );
于 2011-04-19T10:29:17.447 に答える
1

form.phpを次のように変更します

    <?php 

if ($_POST["email"]<>'') { 
    $ToEmail = 'onjegolders@gmail.com'; 
    $EmailSubject = 'Site contact form '; 
    $mailheader = "From: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
    $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
    $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
    $MESSAGE_BODY = "Telephone: ".$_POST["tel"]."<br>";
    $MESSAGE_BODY = "Type: ".$_POST["type"]."<br>";
    $MESSAGE_BODY = "Subject: ".$_POST["subject"]."<br>";
    $MESSAGE_BODY = "Level: ".$_POST["level"]."<br>";
    $MESSAGE_BODY = "Hours required: ".$_POST["hours"]."<br>";
    $MESSAGE_BODY .= "Additional information: ".nl2br($_POST["info"])."<br>"; 
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 

echo &lt;&lt;&lt;EXCERPT

<html>

    <h3>Thanks for your email</h3>
    <h4>I'll get back to you as soon as possible</h4>
    <a href="index.html"><p>Click here to go back to previous page</p></a>

</html>

EXCERPT;

} else { 


echo "<html>Sorry, this form didn't work</html>";

} 
?>
于 2011-04-19T10:43:18.027 に答える
0

これを試してみてください:

if(!empty($_POST["email"])){
  //your email preparation code
}

これを使用することを目的としています:

if($_POST["email" <> ''){
  //your email preparation code
}

!基本的にはないという意味なので、空ではない!emptyという意味です

于 2011-04-19T10:40:32.683 に答える
0

あなたの

if ($_POST["email"] <> '') { 

それをに変えて

 if ($_POST["email"] != '') { 
于 2011-04-19T10:35:51.113 に答える
0

次のように使用することもできます。

if ($_POST["email"]) { 

!= ""これはorempty()チェックと同じように機能します。PHP は、フォームを適切に処理するために導入されました。そして、受信フォームフィールドをプローブさせることができます。文字列に対していくつかの魔法のブール変換ルールを使用します。ほとんどの場合、これで目的が達成されます。

この単純なスタイルのもう 1 つの利点は、E_ALL および E_NOTICE (=debug) error_reporting モードを有効にすると、デバッグが容易になることです。

于 2011-04-19T10:50:18.100 に答える