【问题标题】:PHP Form sends email but without the entered text [duplicate]PHP表单发送电子邮件但没有输入的文本[重复]
【发布时间】:2019-07-08 23:54:58
【问题描述】:

我收到了一份表格,希望将填写好的表格发送到我的电子邮件地址。 我的代码不能正常工作(我对 PHP 没有太多经验)。 所以 - 我收到一封电子邮件,但没有输入表单的文本。 我的代码中有什么遗漏或错误?

<!--Contact-->
<section id="contact" class="get-in-touch">
  <h1 class="title">Contact <span>us!</span></h1>
  <p class="contact-p text-center">Lorem Ipsum.</p>
  <form class="contact-form row" method="GET" action="contact_me.php">
    <div class="form-field col x-50">
      <input id="name" class="input-text js-input" type="text" required>
      <label class="label" for="name">Name</label>
    </div>
    <div class="form-field col x-50">
      <input id="email" class="input-text js-input" type="email" required>
      <label class="label" for="email">E-Mail</label>
    </div>
    <div class="form-field col x-100">
      <input id="message" class="input-text js-input" type="text" required>
      <label class="label" for="message">Message</label>
    </div>
    <div class="form-field col x-100 align-center">
      <input class="submit-btn" type="submit" value="Send">
    </div>
  </form>
</section>
    <?php
$name = $_GET['name'];
$email_address = $GET['email'];
$message = $GET['message'];

// Create the email and send the message
$to = 'user@gmail.com'; //This is where the form will send a message to.
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from.
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);          
?>


所以我希望收到输入姓名、电子邮件和消息的电子邮件,但我只收到了 $email_body 的文本,没有输入用户的文本。它只是空白。

输出如下所示: Output
您已收到来自您的网站联系表单的新消息。

以下是详细信息:

姓名:

电子邮件:

消息:

【问题讨论】:

    标签: php html css email


    【解决方案1】:

    您的&lt;input /&gt; 元素需要name="" 属性才能在$_GET$_POST 中可用。

    【讨论】:

    • 这显然是一个重复的问题/答案
    【解决方案2】:

    你必须使用 mailto 函数然后设置一个本地主机并设置一个变量来发送电子邮件和管理员名称你可以看这个https://www.youtube.com/watch?v=No8gaqsFdMw

    【讨论】:

    猜你喜欢
    • 2019-01-13
    • 1970-01-01
    • 2018-02-12
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多