php中的联系表单不起作用

时间:2014-09-13 17:59:01

标签: php

  if (isset($_REQUEST['email']))  {

  //Email information
  $admin_email = "neelaitken@hotmail.com";

  $name = $_REQUEST['name'];

  $email = $_REQUEST['email'];

  $subject = $_REQUEST['subject'];

  $comment = $_REQUEST['comment'];




  //send email

  mail($admin_email, $name, "$subject", $comment, "From:" . $email);

  //Email response

  echo "Thank you for contacting us!";
  }

  //if "email" variable is not filled out, display the form

  else  {

          ?>

 <form method="post">

                                  <div>
                                <span><input name="name" type="text" class="textbox" value="Name:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name*';}"></span>
                            </div>

                            <div>
                                <span><input name="email"  type="text" class="textbox" value="Email:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email*';}"></span>
                            </div>




                            <div>
                                <span><input name="subject" type="text" class="textbox" value="mobile:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'subject and phone*';}"></span>
                            </div>

                            <div>
                                <span><textarea name="comment" value="Message:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Message*';}">Message</textarea></span>
                            </div>

                           <div>
                                <span><input type="submit" value="Submit"></span>
                          </div>  
<?php } ?>

1 个答案:

答案 0 :(得分:0)

mail()的参数不正确。试试这个:

mail($admin_email, $subject, $comment, "From: " . $email);

当您有$to, $subject, $message时,它们必须为$to, $name, $subject, $message(不包括可选参数)。