为什么';这张PHP联系人表单是否发送电子邮件?
这是一个非常基本的问题,但我一点也搞不懂。当这个PHP表单提交时,它不会发送电子邮件,我也不知道为什么。我希望你们能帮忙为什么';这张PHP联系人表单是否发送电子邮件?,php,html,Php,Html,这是一个非常基本的问题,但我一点也搞不懂。当这个PHP表单提交时,它不会发送电子邮件,我也不知道为什么。我希望你们能帮忙 <?php if($_POST['submit']){ $to = "email@email.com"; $from = $_POST['email']; $name = $_POST['name']; $subject = "Form submission"; $message = $name . " wrote the fo
<?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' ) ;
}
?>
姓名:
电邮地址:
信息:
谢谢请按此方式检查:
<?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";
}
}
?>
在HTML文件中
form action=”“method=“post”
应该这样做(如果您当然在php中包含HTML)有什么错误?请尝试
if(mail($to,$subject,$message,$headers)){echo'sent'}或者{echo'not sent'}
可能是因为缺少表单标记?你能从你的服务器发送邮件吗?您确定已安装邮件列表并准备启动吗?是否尝试在本地主机上执行此操作?请检查您的smtp设置。如果邮件未发送,它只会隐藏邮件,不会解释邮件未发送的原因。。。
<?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";
}
}
?>