[英]Why doesn't this PHP Contact Form Send An Email?
这是一个非常基本的问题,但我根本无法弄清楚。 提交此 PHP 表单时,它不会发送电子邮件,我不知道为什么。 我希望你们能帮忙。
<?php
if($_POST['submit']){
$to = "email@email.com";
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Form submission";
$message = $name . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
header( 'Location: http://example.com' ) ;
}
?>
<container class="form">
<table class="formtable" align="center">
<form action="formcontact.php" method="post">
<tr><td align="center" class="tabletitle">Name:</td></tr><tr class="space"><td align="center"><input type="text" name="name"></td></tr>
<tr><td align="center" class="tabletitle">Email Address:</td></tr><tr class="space"><td align="center"><input type="text" name="email"></td></tr>
<tr><td align="center" class="tabletitle">Message:</td></tr><tr class="space"><td align="center"><textarea rows="5" name="message" cols="30"></textarea></td></tr>
<tr><td align="center"><input type="submit" name="submit" value="submit"></td></tr>
</table>
</container>
谢谢
在您的 HTML 文件中
表单动作=“”方法=“发布”
应该可以解决问题(当然,如果您将 HTML 包含在 php 中)
以这种方式检查:
<?php
if($_POST['submit']){
$to = "email@email.com";
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Form submission";
$message = $name . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
if(mail($to,$subject,$message,$headers)){
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
header( 'Location: http://example.com' ) ;
}else
{
echo "Mail failed to Sent";
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.