简体   繁体   English

PHP联系表格不会发送

[英]PHP contact form won't send

I cannot get my PHP contact form to work correctly. 我无法使我的PHP联系人表格正常工作。 I am trying to complete it in one page and would appreciate any help. 我正在尝试在一页上完成它,希望对您有所帮助。 I would like to keep it in a table format. 我想将其保留为表格格式。 I have searched but have not been able to find the correct formatting for POST/if isset. 我已经搜索过,但无法找到POST / if isset的正确格式。 Any help would be greatly appreciated. 任何帮助将不胜感激。

PHP: 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>

no need for use echo on each line..u can use likethis.. 不需要在每一行上使用echo。.u可以这样使用。

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

u will need header too, 您也将需要标头,

$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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM