使用php联系我们表格无法正常工作

时间:2017-04-11 04:55:22

标签: php html email

这里我使用了两个文件contact_us.php& mail.php

它没有给出任何错误但没有收到邮件,请在下面的代码中帮我解决任何问题。

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 \n Message: $message";
$recipient = "myid@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";

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

?>

1 个答案:

答案 0 :(得分:0)

没有名称的字段:名称,电子邮件,消息等等:$ _POST ['recipient'],$ _POST ['subject'],$ _POST ['formcontent'],$ _POST ['mailheader']

尝试以下代码或更改

形式的字段名称
        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*/

}