Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP联系人表单在我添加$headers时发送多封电子邮件_Php_Email_Contact_Contact Form - Fatal编程技术网

PHP联系人表单在我添加$headers时发送多封电子邮件

PHP联系人表单在我添加$headers时发送多封电子邮件,php,email,contact,contact-form,Php,Email,Contact,Contact Form,我有一个发送电子邮件的联系人表单,但将我的电子邮件服务器显示为“发件人”,因此很难回复从联系人表单发送的电子邮件 我试着添加 $headers = 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); 我的脚本,但虽然这是完美的工作,就发送电子邮件,你可以回复,它仍然发送电子邮件,你不能回复 我是一个PHP新手,所以我想我在发送两条消息

我有一个发送电子邮件的联系人表单,但将我的电子邮件服务器显示为“发件人”,因此很难回复从联系人表单发送的电子邮件

我试着添加

$headers = 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
我的脚本,但虽然这是完美的工作,就发送电子邮件,你可以回复,它仍然发送电子邮件,你不能回复

我是一个PHP新手,所以我想我在发送两条消息时犯了一个错误,如果有人能指出这是什么,我将不胜感激,因为尽管我在这里看到了其他类似的问题,但我找不到解决方案

这是我的密码:

include ("includes/header.php");
$pagetitle   = "Contact Us";
$description = "";
$keywords    = "";
$name        = ($_POST['name']);
$email       = ($_POST['email']);
$message     = ($_POST['message']);
$from        = ($_POST['email']);
$to          = 'info@mydomain.co.uk'; 
$subject     = "Enquiry from Visitor " . $name;
$human       = ($_POST['human']);
$headers     = 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

<div class="container-fluid contactform">
   <div class="col-md-6 contactform-padding">   
     <h2>Contact Us</h2>

<?php 
    if (isset($_POST['submit']) && $human == '4') {              
      if (mail ($to, $subject, $body, $from)) { 
         echo '<p>Thanks for getting in touch. Your message has been sent & We will get back to you shortly!</p>';
       } else { 
          echo '<p>Something went wrong, go back and try again!</p>'; 
       }  
    } else if (isset($_POST['submit']) && $human != '4') {
       echo '<p>You answered the anti-spam question incorrectly!</p>';
    }
?>

 <form method="post" action="index.php" data-ajax="false" method="POST" enctype="multipart/form-data">
 <div class="form-group">
  <label class="control-label " for="name">
   <p>Name</p>
  </label>
  <input class="form-control" id="name" name="name" type="text"/>
 </div>
include(“includes/header.php”);
$pagetitle=“联系我们”;
$description=“”;
$keywords=“”;
$name=($_POST['name']);
$email=($_POST['email']);
$message=($_POST['message']);
$from=($_POST['email']);
$to$info@mydomain.co.uk'; 
$subject=“访客询问”$名称
$human=($_POST['human']);
$headers='回复:'$电子邮件。“\r\n”。”X-Mailer:PHP/”。phpversion();
邮件($to、$subject、$message、$headers);
?>
联系我们
名字

请有人告诉我为什么这会发送两封电子邮件?我真的很感激——我知道我犯了一个愚蠢的错误,我不知道为什么/如何


谢谢

请再次检查代码

您正在调用邮件功能两次。 一个处于上述状态,另一个处于if状态

从上述代码中删除邮件功能


邮件可以从您的if条件下发送

嘿,谢谢,是的,它在同一个文件中-它在索引中,但这将联系人表单设置为空白页?抱歉-上面的代码在同一个文件中,我的联系人表单isI在index.php中有上面的代码,但它将我的联系人表单设置为空白页,而不是带有它会把我带到顶部带有感谢信息的页面,而不是停留在联系人页面上!请使用ajax。Google:ajax联系人表单