douxiza9868 2017-04-11 04:55
浏览 63
已采纳

使用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 2017-04-11 05:20
    关注

    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*/
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里