php联系人表单不工作,错误消息&;反弹
因此,当涉及到php表单时,我真的很糟糕,我收到的信息是“对不起, 无法发送您的邮件…请检查您的电子邮件是否正确,否则将丢失一个字段…” 其他人正在使用该网站,说它也在反弹 该文件夹不在php文件夹中,而是与html页面一起显示php联系人表单不工作,错误消息&;反弹,php,web,contact,Php,Web,Contact,因此,当涉及到php表单时,我真的很糟糕,我收到的信息是“对不起, 无法发送您的邮件…请检查您的电子邮件是否正确,否则将丢失一个字段…” 其他人正在使用该网站,说它也在反弹 该文件夹不在php文件夹中,而是与html页面一起显示 <?php //set your email here: $yourEmail = 'emma@peacehavengc.com'; /* * CONTACT FORM */ //If the form is submitted if(isset($_PO
<?php
//set your email here:
$yourEmail = 'emma@peacehavengc.com';
/*
* CONTACT FORM
*/
//If the form is submitted
if(isset($_POST['submitted'])) {
//Check to make sure that the name field is not empty
if($_POST['contact_name'] === '') {
$hasError = true;
} else {
$name = $_POST['contact_name'];
}
//Check to make sure sure that a valid email address is submitted
if($_POST['emma@peacehavengc.com'] === '') {
$hasError = true;
} else if (!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $_POST['emma@peacehavengc.com'])) {
$hasError = true;
} else {
$email = $_POST['emma@peacehavengc.com'];
}
//Check to make sure comments were entered
if($_POST['contact_textarea'] === '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes($_POST['contact_textarea']);
} else {
$comments = $_POST['contact_textarea'];
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = $yourEmail;
$subject = "Message From Your Website";
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From : my site <'.$emailTo.'>' . "\r\n" . 'answer to : ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
HTML
<div class="center">
<h3>Get in touch Now</h3>
</div>
<form class="form-horizontal" method="post" action="contact.php" id="form">
<div class="form-group">
<label for="contact_name" class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="contact_name" name="contact_name">
</div>
</div>
<div class="form-group">
<label for="contact_email" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input type="email" class="form-control" id="contact_email" name="contact_email">
</div>
</div>
<div class="form-group">
<label for="contact_textarea" class="col-lg-2 control-label">Message</label>
<div class="col-lg-10">
<textarea class="form-control" rows="3" id="contact_textarea" name="contact_textarea"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit" class="btn btn-default" name="submitted"><i class="icon-paperplane"></i>Send</button>
</div>
</div>
</form>
现在就联系
名称
电子邮件
消息
邮寄
检查此项
<?php
$yourEmail = 'emma@peacehavengc.com';
if(isset($_POST['submitted']))
{
if($_POST['contact_name'] == '')
{
$hasError = true;
}
else
{
$name = $_POST['contact_name'];
}
//Check to make sure sure that a valid email address is submitted
if($_POST['contact_email'] == '')
{
$hasError = true;
}
else if (!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $_POST['contact_email']))
{
$hasError = true;
}
else
{
$email = $_POST['contact_email'];
}
//Check to make sure comments were entered
if($_POST['contact_textarea'] == '')
{
$hasError = true;
}
else
{
if(function_exists('stripslashes'))
{
$comments = stripslashes($_POST['contact_textarea']);
}
else
{
$comments = $_POST['contact_textarea'];
}
}
//If there is no error, send the email
if(!isset($hasError))
{
$emailTo = $yourEmail;
$subject = "Message From Your Website";
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = "From: my site <$emailTo>" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\r\n";
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
header("location:contact.html");
}
?>
请在问题中添加您的代码,好吗?这是什么$\u POST['emma@peacehavengc.com']; ? 你有这样的输入名称吗?将HTML联系人表单的代码粘贴到我不认为我犯了一点错误,我只需要将需要联系的人的电子邮件放在右上方?显示你的联系人表单。我是否需要将电子邮件放在底部,上面写着“如果没有错误,发送电子邮件”将她的电子邮件放在“$youremail;”??因此,现在,电子邮件发送后的屏幕是空白的,您没有给出任何标题位置以重定向到contact.html页面。这就是@SaciBasaranNow使用的原因。我编辑了我的答案。在页面的末尾,我添加了标题位置。使用你否决了我的答案?我什么都没否决,甚至不知道怎么做?我会试试你说的谢谢