douxiza9868
douxiza9868
2017-04-11 04:55

使用php联系我们表单无法正常工作[复制]

已采纳

This question already has an answer here:

Here i used two files contact_us.php & mail.php

its not gives any error but not getting mail, please help me any thing wrong in below code.

contact_us.php

<!DOCTYPE HTML>
<html>
<head>
  <title>TPC</title>
  <meta name="description" content="website description" />
  <meta name="keywords" content="website keywords, website keywords" />
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <link rel="stylesheet" type="text/css" href="style/style.css" title="style" />
</head>

<body>
<form action="mail.php" method="post">
Name: <input class="contact" type="text" name="your_name" value="" /><br><br>
Email Address: <input class="contact" type="text" name="your_email" value="" /><br><br>
Message: <textarea class="contact textarea" rows="8" cols="50" name="your_enquiry"></textarea><br><br>
<p style="padding-top: 15px"><span>&nbsp;</span><input class="submit" type="submit" name="submit" value="submit" /></p>
</form>
</body>
</html>

mail.php

<?php 
    if(isset($_POST['submit'], $_POST['name'], $_POST['email'], $_POST['message'], $_POST['recipient'], $_POST['subject'], $_POST['formcontent'], $_POST['mailheader'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name 
 Message: $message";
$recipient = "myid@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email 
";

mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    };
echo "Thank You!";

?>
</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dth54864 dth54864 4年前

    There are no fields with name: name, email, message and nothing like: $_POST['recipient'], $_POST['subject'], $_POST['formcontent'], $_POST['mailheader']

    try code below or change the names of the fields in the form

            if(isset($_POST['submit'], $_POST['your_name'], $_POST['your_email'], $_POST['your_enquiry'])) {
        $name = $_POST['your_name'];
        $email = $_POST['your_email'];
        $message = $_POST['your_enquiry'];
    
    /* rest whatever you are trying to do*/
    
    }
    
    点赞 评论 复制链接分享

相关推荐