PHP联系表格不会发送

时间:2013-09-25 04:53:38

标签: php email contact-form

我无法让我的PHP联系表单正常工作。我试图在一个页面上完成它,并将感谢任何帮助。我想以表格格式保留它。我已搜索但无法找到POST / ifset的正确格式。任何帮助将不胜感激。

PHP:

   <html>
    <body>


    <?php 
    $action=$_REQUEST['action']; 
    if ($action=="")
    {
    echo "<table width=\"360\" cellpadding=\"2\" cellspacing=\"0\">";
    echo "  <tr>";
    echo "      <td width=\"20%\"><span id=\"rfvname\">* Name:</span></td>";
    echo "      <td><input type=\"text\" name=\"name\" value=\"\" /></td>";
    echo "  </tr>";
    echo "  <tr>";
    echo "          <td><span id=\"rfvemail\">* Email:</span></td>";
    echo "         <td><input type=\"text\" name=\"email\" value=\"\" /></td>";
    echo "  </tr>";
    echo "  <tr>";
    echo "        <td>Comments:</td>";
    echo "         <td><textarea name=\"comments\" rows=\"5\" cols=\"15\"></textarea></td>";
    echo "  </tr>";
    echo "  <tr>";
    echo "         <td>&nbsp;</td>";
    echo "         <td><input type=\"submit\" value=\"Submit\" class=\"btnSubmit\" id=\"btnSubmit\" name=\"submit\" /></td>";
    echo "  </tr>";
    echo "</table> ";
    }
    else
        { 
        $name=$_REQUEST['name']; 
        $email=$_REQUEST['email']; 
        $comments=$_REQUEST['comments']; 
        if (($name=="")||($email=="")||($comments=="")) 
            { 
            echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
            } 

     else{         

            $to      = 'email@email.com';
            $from="From: $name<$email>\r\nReturn-path: $email"; 
            $subject="Message sent using your contact form"; 
            mail($to, $subject, $comments, $from); 
            echo "Email sent!"; 
            } 
        }   
    ?> 

    </body>
    </html>

1 个答案:

答案 0 :(得分:0)

不需要在每一行上使用回声..我可以使用likethis ..

echo "<table width=\"360\" cellpadding=\"2\" cellspacing=\"0\">
      <tr> & so on....";

你也需要标题,

$to      = 'email@email.com';
$from= $email; 
$subject="Message sent using your contact form"; 
$msg = "blah blah";

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;

mail($to, $subject, $msg, $headers);