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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料