在HTML和PHP中发送表单电子邮件不起作用
我在我的网站上创建了一个表单,让其他人与我联系。我使用PHP脚本发送电子邮件,但我总是收到错误: 此XML文件似乎没有任何与之关联的样式信息。文档树如下所示 我使用了以下代码:在HTML和PHP中发送表单电子邮件不起作用,php,html,web,Php,Html,Web,我在我的网站上创建了一个表单,让其他人与我联系。我使用PHP脚本发送电子邮件,但我总是收到错误: 此XML文件似乎没有任何与之关联的样式信息。文档树如下所示 我使用了以下代码: <form method="post" action="contact.php" enctype="text/plain"> Name*:<br> <input type="text" name="name" placeholder='Steve'><br>
<form method="post" action="contact.php" enctype="text/plain">
Name*:<br>
<input type="text" name="name" placeholder='Steve'><br>
E-mail*:<br>
<input type="text" name="mail" placeholder='john@example.com'><br>
Comment*:<br>
<textarea name="comments" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
<br> <br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
姓名*:
电子邮件*:
评论*:
这个网站太棒了!
在html中,并且此:
<?php
if($_POST["message"]) {
mail("myemail@example.com", "MCPEmaps Comment", $_POST["message"], "From: an@email.address");
}
?>
在PHP文件中
有什么帮助吗?使用此更改您的html,因为您正在使用
$\u POST[“message”]
,但您没有在html中传递它。。所以,改变你的路线
完整代码如下:
<form method="post" action="contact.php" enctype="text/plain">
Name*:<br>
<input type="text" name="name" placeholder='Steve'><br>
E-mail*:<br>
<input type="text" name="mail" placeholder='john@example.com'><br>
Comment*:<br>
<textarea name="comments" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
<br> <br>
<input type="submit" name="message" value="Send">
<input type="reset" value="Reset">
</form>
姓名*:
电子邮件*:
评论*:
这个网站太棒了!
PHP不会发送邮件,因为没有输入:message
您可以使用:
<?php
if(isset($_POST["message"])) {
mail("myemail@example.com", "MCPEmaps Comment", $_POST["message"], "From: an@email.address");
}
?>
及
在contact.php文件中尝试以下代码:
<?php
if($_POST["comments"]) {
mail("myemail@example.com", "MCPEmaps Comment", $_POST["message"], "From: an@email.address");
}
?>
如果您在localhost中使用,则需要在php.ini文件中进行大量工作。否则你会得到结果 您发布的是
评论
,而不是消息
更改此项:
<textarea name="comments" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
这个网站太棒了!
为此:
<textarea name="message" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>
这个网站太棒了!
你能显示错误消息吗?你是在服务器或本地主机上尝试的吗?你没有从FORM传递消息。这是第二个代码片段contact.php
?@justbaron是的。他们还必须将$\u POST['message']
更改为$\u POST['comments']
在PHPmail
方法中。仍然会给我错误:此XML文件似乎没有任何与之关联的样式信息。文档树如下所示。
<textarea name="message" maxlength="400" cols="25" rows="6">
This site is awesome!
</textarea>