0

いいえ、このフォームは初めてです。

お問い合わせフォームページの設定に成功しました。フォームフィールドから「メールアドレス」と「メッセージ」をメールで送信しますが、名前フィールドの値は送信せず、空白です。

どこが間違っているのかわかりません。すべてのフィールド名は PHP ファイルと一致します。私が間違っていることについてのアイデアはありますか?

これが私のコードです:

   <form id="form_28" name="website_query" action="mailform2.php" accept-charset="UTF-8" method="post" target="_self" enctype="multipart/form-data" style="margin:0;position:absolute;left:231px;top:242px;width:343px;height:229px; /*MainDivStyle*/" __AddCode="here">
<!--MainDivStart-->


<!-- HTML Frame - name txt_31 -->

<!--Preamble-->
<div style="position:absolute;left:8px;top:8px;width:51px;height:18px;overflow:hidden; /*BorderDivStyle*/" __AddCode="InsideBorderDiv">
<!--BorderDivContents-->
<p class="Wp-Body-P"><label for="edit_1"><span class="Body-C">name</span></label></p>
</div>
<!--Postamble-->


<!-- Form Edit box edit_1 -->

<!--Preamble-->
<input type="text" id="edit_1" name="name" value="" style="position:absolute; left:103px; top:8px; width:50px; /*Tag Style*/" __AddCode="here">
<!--Postamble-->


<!-- HTML Frame - email txt_32 -->

<!--Preamble-->
<div style="position:absolute;left:8px;top:38px;width:51px;height:18px;overflow:hidden; /*BorderDivStyle*/" __AddCode="InsideBorderDiv">
<!--BorderDivContents-->
<p class="Wp-Body-P"><label for="edit_19"><span class="Body-C">email</span></label></p>
</div>
<!--Postamble-->


<!-- Form Edit box edit_19 -->

<!--Preamble-->
<input type="text" id="edit_19" name="email" value="" style="position:absolute; left:103px; top:38px; width:50px; /*Tag Style*/" __AddCode="here">
<!--Postamble-->


<!-- HTML Frame - message txt_33 -->

<!--Preamble-->
<div style="position:absolute;left:8px;top:68px;width:79px;height:18px;overflow:hidden; /*BorderDivStyle*/" __AddCode="InsideBorderDiv">
<!--BorderDivContents-->
<p class="Wp-Body-P"><label for="text_2"><span class="Body-C">message</span></label></p>
</div>
<!--Postamble-->


<!-- Text Area text_2 -->

<!--Preamble-->
<textarea id="text_2" name="message" rows="2" cols="10" style="position:absolute; left:103px; top:68px; width:100px; height:38px; /*Tag Style*/" __AddCode="here"></textarea>
<!--Postamble-->


<!-- HTML Frame - captcha txt_34 -->

<!--Preamble-->
<div style="position:absolute;left:8px;top:114px;width:69px;height:18px;overflow:hidden; /*BorderDivStyle*/" __AddCode="InsideBorderDiv">
<!--BorderDivContents-->
<p class="Wp-Body-P"><label for="captcha_1"><span class="Body-C">captcha</span></label></p>
</div>
<!--Postamble-->


<!-- Form CAPTCHA captcha_1 -->

<!--Preamble-->
<div style="position:absolute;left:103px;top:114px;width:190px;height:69px; /*MainDivStyle*/" __AddCode="here">
<!--MainDivStart-->
    <img src="http://www.serifwebresources.com/util/img_verify.php?gen_word=1&id=captcha_1"><br><input type="text" id="captcha_1" name="captcha_1" size="20" __AddCode="here">
    <a title="Listen to audio CAPTCHA" href="http://www.serifwebresources.com/util/audio/audio.php"><img alt="Listen to audio CAPTCHA" style="vertical-align: middle" src="http://www.serifwebresources.com/media/icons/audio-desc.png" border="0"></a><!--MainDivEnd-->
</div>
<!--Postamble-->


<!-- Form Button butn_4 -->

<!--Preamble-->
<input type="submit" style="position:absolute; left:8px; top:191px; width:81px; height:22px; /*Tag Style*/" value="Submit" __AddCode="here">
<!--Postamble-->
</form>

PHP のコード (mailform2.php):

  <?php 
$errors = '';
$myemail = 'myemail';//<-----Put Your email address here.
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['message']))

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


if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Website Query: $name";
    $email_body = "You have received a new message. ".
    " Here are the details:\n Name: $name \n Email: $email \n Message \n $message"; 

    $headers = "From: $myemail\n"; 
    $headers .= "Reply-To: $email";

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: contact-form-thank-you.html');
} 
?>
4

4 に答える 4

1
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['message']))

$name = $_POST['name']; 

上記のコードでは、名前、電子メール、およびメッセージの投稿が空の場合、name = $_POST['name']; を設定します。

SO $name 変数が設定されていません。

したがって、これらのようなコード

    if(empty($_POST['name'])  || 
           empty($_POST['email']) || 
           empty($_POST['message'])) {
        $errors = 'Please enter all required fields';
    }
    else
    {
     $name = $_POST['name']; 
     $email = $_POST['email']; 
     $message = $_POST['message'];
   } 
于 2013-04-20T01:56:15.273 に答える
0
if(!isset($_POST['name'])  && !isset($_POST['email']) && !isset($_POST['message'])) {
   $name = $_POST['name']; 
   $email = $_POST['email']; 
   $message = $_POST['message']; 
}else{
   $errors = ''; //process
}

中括弧を追加します。中括弧がありません。したがって、すべての POST 変数に値がある場合、name 変数は設定されません。他の 2 つは、中括弧がないと if ステートメントが最初のステートメントの後に終了するためです。

編集、あなたの論理も間違っていると思います。これらの値がすべて空でない場合は、処理する必要があります。

于 2013-04-20T02:05:09.133 に答える
0

value=''送信する場合は、削除してみてください

<input type="text" id="edit_1" name="name" style="position:absolute; left:103px; top:8px; width:50px; /*Tag Style*/" __AddCode="here">

それが機能するかどうかを確認してください!

編集および追加

sumbit のvalue名前を次のように変更します。name='submit'

<input type="submit" style="position:absolute; left:8px; top:191px; width:81px; height:22px; /*Tag Style*/" name="submit" __AddCode="here">  

そして、php の部分を次のように変更したいかもしれません:

<?php
$errors = '';
$myemail = 'myemail';//<-----Put Your email address here.

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

if(isset($_POST['sumbit']) && (
    empty($_POST['name'])  ||
    empty($_POST['email']) ||
    empty($_POST['message'])))
    {
        echo "Please fill up the fields";
    }
    elseif(isset($_POST['sumbit']) && empty($errors)){
    $to = $myemail;
    $email_subject = "Website Query: $name";
    $email_body = "You have received a new message. ".
    " Here are the details:\n Name: $name \n Email: $email \n Message \n $message";

    $headers = "From: $myemail\n";
    $headers .= "Reply-To: $email";

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: contact-form-thank-you.html');
}
?>
于 2013-04-20T01:58:22.357 に答える
0

さて、ここでデバッグしました。これが修正された作業コードです。空ではなく isset を使用する必要があります

<?php 

$errors = '';
$myemail = 'myemail';//<-----Put Your email address here.
if(isset($_POST['name'])  || 
   isset($_POST['email']) || 
   isset($_POST['message'])) { 


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


}

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Website Query: $name";
    $email_body = "You have received a new message. ".
    " Here are the details:\n Name: $name \n Email: $email \n Message \n $message"; 

    $headers = "From: $myemail\n"; 
    $headers .= "Reply-To: $email";

    //redirect to the 'thank you' page
    header('Location: contact-form-thank-you.html');
} 


?>

また、if ループについても説明しました。そこにある if ループ内にもメール送信コードを入れることができます。

お役に立てれば

于 2013-04-20T02:07:41.970 に答える