0

我无法让我的 PHP 联系表正常工作。我正在尝试在一页中完成它,并希望得到任何帮助。我想将其保留为表格格式。我已经搜索过,但找不到正确的 POST/if isset 格式。任何帮助将不胜感激。

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>
4

1 回答 1

0

无需在每一行上使用 echo ..u 可以这样使用 ..

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);
于 2013-09-25T05:00:06.827 回答