简体   繁体   中英

PHP contact form won't send

I cannot get my PHP contact form to work correctly. 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. Any help would be greatly appreciated.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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