douzhi1919 2012-09-19 09:27
浏览 26
已采纳

发送HTML电子邮件时$ _POST不起作用

I've been figuring out what's wrong with my code. I keep getting $_POST not working. This is my HTML code:

<form id="EmailForm" action="mailForm.php" method="post" 
  onsubmit="validateForm()" enctype="text/plain">
  <div>
    Name: <input type="text" value="" name="name" size="30" />
    Email: <input type="text" value="" name="email" size="30" />
    Subject: <input type="text" value="" name="subject" size="60" />
    Message: <br />
    <textarea name="message" rows="5" cols="60"></textarea>
    <input type="submit" value="Send" />
  </div>
</form>

This is my mailForm.php code:

<?php
$name = $_POST['name']; 
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$mailsent = mail("admin@example.com", "$subject", "$message

$name
$email", "");
if ($mailsent) {
echo ("Your email has been sent. Thank you for using our mail form. <br />");
echo ("Name: ".$name."<br />");
echo ("Email: ".$email."<br />");
echo ("Subject: ".$subject."<br />");
echo ("Message: ".$message);
}
?>

So far, I can get emails sent but all emails are empty. The name or email didn't show up, but get changed to the default name from the web hosting service. No name, no email, no subject, no message. At the mailForm.php, I got the following only:

Your email has been sent. Thank you for using our mail form.   
Name:
Email:
Subject: 
Message:

I've tried echo $_POST["name"]; echo $_POST["email"] but got empty page.

  • 写回答

2条回答 默认 最新

  • dqm83011 2012-09-19 09:30
    关注

    Just remove the enctype="text/plain":

    <form id="EmailForm" action="mailForm.php" method="post" onsubmit="validateForm()">
    

    Valid values in PHP for enctype in <form> tag are:

    application/x-www-form-urlencoded
    multipart/form-data
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作