0

我不能让它正常工作。我知道它有些愚蠢,但我找不到它。

<?php

$mailto   = "stormygurl73@yahoo.com";  
$name     = ucwords($_POST['name']); 
$subject  = $_POST['Contact form'];
$email    = $_POST['email'];
$message  = $_POST['message'];

    if(strlen($_POST['name']) < 1 ){
        echo  'email_error';
    }

  else if(strlen($email) < 1 ) {
        echo 'email_error';
    }

  else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", $email)) {
    echo 'email_error';
  }

    else if(strlen($message) < 1 ){
        echo 'email_error';

  } else {

    // NOW SEND THE ENQUIRY

    $email_message="\n\n" .
        "Name : " .
        ucwords($name) .
        "\n" .
        "Email : " .
        $email .
        "\n\n" .
        "Message : " .
        "\n" .
        $message .
        "\n" .
        "\n\n" ;

        $email_message = trim(stripslashes($email_message));
        mail($mailto, $subject, $email_message, "From: \"$vname\" <".$email.">\nReply-To: \"".ucwords($name)."\" <".$email.">\nX-Mailer: PHP/" . phpversion() );

}
?>

html

<div class="wrapper">
    <div id="main" style="padding:50px 0 0 0;">
    <form id="contact-form" action="sendemail.php" method="post">
      <h3>Get in touch</h3>
      <h4>Fill in the form below, and we'll get back to you within 24 hours.</h4>
      <div>
        <label>
          <span>Name: (required)</span>
          <input placeholder="Please enter your name" type="text" tabindex="1" required autofocus>
        </label>
      </div>
      <div>
        <label>
          <span>Email: (required)</span>
          <input placeholder="Please enter your email address" type="email" tabindex="2" required>
        </label>
      </div>

      <div>
        <label>
          <span>Message: (required)</span>
          <textarea placeholder="Include all the details you can" tabindex="5" required></textarea>
        </label>
      </div>
      <div>
        <button name="submit" type="submit" id="contact-submit">Send Email</button>
      </div>
    </form>
    <!-- /Form -->

任何帮助都是极好的!

4

2 回答 2

2

您的输入元素必须具有 name 属性。第一个应该有

 name="name" 

等等。您可以在此处阅读更多相关信息:来自外部源的变量:HTML 表单(GET 和 POST)

于 2013-10-08T16:03:21.823 回答
0

看起来您在表单字段中的任何地方都错过了属性名称。 name='somename'例如,这就是你所拥有的

<input placeholder="Please enter your name" type="text" tabindex="1" required autofocus>

这是应该的

<input name="name" placeholder="Please enter your name" type="text" tabindex="1" required autofocus>
于 2013-10-08T16:15:12.387 回答