PHP没有抓取表单信息

时间:2014-07-18 15:33:08

标签: php html forms email

我对PHP比较陌生,而且我无法让我的PHP获取表单数据并通过电子邮件提交。电子邮件向我发送了我的简单文本,但所有表单数据都没有。有没有人对什么是错误的想法?

这是HTML:

<div id="box3" class="clearfix">
        <form action="contact.php" method="post" enctype="text/plain">
            <div id="greyContainer" class="clearfix">
            <p id="text5">
            Contact Us
            </p>
            <p id="text6">
            Feel free to contact us and leave a message if you have any general questions&#x21;
            </p>

            <label id="formgroup">
                <p id="text7">
                Name&#x3a;
                </p>
                <input id="name" type="text" value="Full Name" name="name"></input>
            </label>
            <label id="formgroup1">
                <p id="text8">
                Number&#x3a;
                </p>
                <input id="phone_number" type="text" value="Phone Number" name="phone_number"></input>
            </label>
            <label id="formgroup2">
                <p id="text9">
                Email&#x3a;
                </p>
                <input id="email" type="text" value="Email Address" name="email"></input>
            </label>
            <label id="formgroup3">
                <p id="text10">
                Message&#x3a;
                </p>
                <textarea id="message_block" name="message_block" >Message or question...</textarea>
            </label>
            <p id="text11">
            <span id="textspan">AVA Roofing &amp; Siding<br />12 Arcade Ave.<br />Amherst, NY 14226<br />716.602.3947</span><br />&nbsp;
            </p>
            <img id="image1" src="img/envelope.png" class="image" />
            <a href="thank_you.html">
                <input id="input" type="submit" value="Submit" name="submit" ></input>
            </a>

            <div id="whiteLine" class="clearfix">
            </div>
    </form>
        </div>

    </div>

这是PHP:

<?php
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 $to = "example@gmail.com" ; 
$from = $_POST['email'] ; 
$name = $_POST['name'] ;
$headers = "From: $from"; 
$subject = "AVA Roofing Contact Form"; 
$message2 = $_POST['message_block'];
$number = $_POST['phone_number'];

$message = "A visitor has submitted the following requirements. \n\nName:         $name\n\nEmail: $email\n\nNumber: $number\n\nMessage: $message";

$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to, $subject, $message, $headers);

$send = mail($to, $subject, $message, $headers);  
if($send) 
{header( "Location: http://www.example.com/folder/thank_you.html" );} 
else 
{print "We encountered an error sending your mail, please notify                    webmaster@YourCompany.com"; }

?>

2 个答案:

答案 0 :(得分:5)

您的表单上的编码错误:

<form action="contact.php" method="post" enctype="text/plain">
                                        ^^^^^^^^^^^^^^^^^^^^^

由于您要告诉浏览器将其作为text / plain发送,因此PHP不会处理它。对于这个简单的表单,您不需要指定任何编码。只需接受默认值。

如果您坚持指定编码,则标准表单应为application/x-www-form-urlencoded,如果您正在上传文件,则为multipart/form-data

答案 1 :(得分:0)

您可以发送到file.php等其他文件,并在此文件中执行以下操作:

   $recipiente = "your@email.com ";
   $asunto = "Formulario";
   $message ="name: ".$name."<br>";
   $message .="email: ".$email."<br>";
   $message .="coment: ".$coment."<br>";

   $message = stripslashes($message);

   $headers = "MIME-Version: 1.0\r\n";
   $headers .= "Content-type:text/html; charset=iso-8859-1\r\n";
   $headers .= "From: $email\r\n";
   $headers .= "Reply-to: $email\r\n";
   $headers .= "Cc: $email\r\n";

   mail($recipiente,$asunto,$message,$headers);