无法使用PHP mail()将数据从HTML表单发送到电子邮件
下面是我正在使用的一段代码。虽然我复制粘贴相同的语法,但它无法将完整数据发送到我的邮件。它只发送空白数据,如我收到的电子邮件的屏幕截图所示。 我的代码如下无法使用PHP mail()将数据从HTML表单发送到电子邮件,php,email,Php,Email,下面是我正在使用的一段代码。虽然我复制粘贴相同的语法,但它无法将完整数据发送到我的邮件。它只发送空白数据,如我收到的电子邮件的屏幕截图所示。 我的代码如下 <?php $name=$_POST['name']; $visitor_email=$_POST['email']; $message=$_POST['comment']; $email_from = 'noreply@example.com'; $email_subject = "New Form submissi
<?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".
姓名:
电邮:
消息
提交
这是HTML代码预期结果是什么?-表单中的textarea是否命名为“comment”?你寄表格了吗?可能显示HTML,因为发送显然有效。电子邮件中的文本与PHP中的文本不匹配,请显示确切的代码和HTML。请访问,查看和。做一些研究,搜索相关话题等;如果您遇到问题,请发布您的尝试,记录输入和预期输出,最好是在Sir中,说明问题已得到解决。谢谢你的话。
<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>