繁体   English   中英

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

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

下面是我正在使用的一段代码。 尽管我复制粘贴了相同的语法,但它无法将完整的数据发送到我的邮件中。 它只是发送空白数据,如我得到的 email 的屏幕截图所示

我的代码如下。

<?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);

?>

我正在我的域的实时托管服务器上检查它。

这可能不是您的问题的全部,但鉴于我们看不到您的 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>

这是 HTML 代码

暂无
暂无

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

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