简体   繁体   English

无法使用 PHP 邮件将数据从 HTML 表单发送到 email

[英]Unable to send data from HTML form to email using PHP mail()

Below is the piece of code I am using.下面是我正在使用的一段代码。 Though I copy-paste the same syntax it is unable to send the full data to my mail.尽管我复制粘贴了相同的语法,但它无法将完整的数据发送到我的邮件中。 It just sends the blank data as shown in the screenshot of the email I get它只是发送空白数据,如我得到的 email 的屏幕截图所示

My code is as follows.我的代码如下。

<?php

$name=$_POST['name'];
$visitor_email=$_POST['email'];
$message=$_POST['comment'];

$email_from = 'noreply@example.com';

$email_subject = "New Form submission";

$email_body = "You have received a new message from the user $name.\n".
                            "Here is the message:\n $message".


$to = "dummy@gmail.com";

$headers = "From: $email_from \r\n";
                          
$headers .= "Reply-To: $visitor_email \r\n";
                          
mail($to,$email_subject,$email_body,$headers);

?>

I am checking it on the live hosting server of my domain.我正在我的域的实时托管服务器上检查它。

This may not be the entirety of your problem, but given that we cannot see your HTML, you may want to correct this line which has a period instead of a semicolon:这可能不是您的问题的全部,但鉴于我们看不到您的 HTML,您可能需要更正这条有句点而不是分号的行:

$email_body = "You have received a new message from the user $name.\n".
                            "Here is the message:\n $message".
<form class="form-inline" action="form/contact2.php" method="POST">
        <label for="email">Name:</label>
        <input type="text" id="name" placeholder="Enter Name" name="name">
        <label for="email">Email:</label>
        <input type="email" id="email" placeholder="Enter email" name="email">
        <label for="comment">Message</label>
        <input type="comment" id="comment" placeholder="Enter the message" name="comment">
        <button type="submit">Submit</button>
      </form>

This is the HTML code这是 HTML 代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM