当我在发件人字段中收到两次列表电子邮件的表单响应时


When I receive form response in the from field to lists email twice?

我多年来一直在使用php表单,但知之甚少。。这很危险。。。(几个月前,我花了两天时间才让谷歌重述验证生效,但表单运行正常)。

我现在注意到,当我在outlook 2016的from字段中收到回复时,发件人的电子邮件会出现两次,标题部分没有空格。

因此,当我回复时,我在收件人字段中有两次电子邮件。

我问过主办公司,但他们说帮不了我。

php中的标题如下:示例1:

$headers = "From: $email";  
$headers .= " $email";

我在表单字段中收到了两封电子邮件。

-----Original Message-----
From: sendersemail@gmail.com sendersemail@gmail.com [mailto:sendersemail@gmail.com myemail@gmail.com] 
Sent: 08 November 2015 12:04
To: myemail@gmail.com
Subject: Contact Form
name: Mark 
email: sendersemail@gmail.com 
phone_number: 12345
message: hi

但是,如果我根据另一篇文章更改标题
示例2:

 $headers .= "Reply-To: $email";
 $headers = "From: $email";

然后表单字段将更改为我的username@whm4.bargainhosts.co.uk但不是的两倍

-----Original Message-----
From: username@whm4.bargainhosts.co.uk [mailto:username@whm4.bargainhosts.co.uk] 
Sent: 08 November 2015 12:00
To: myemail@gmail.com
Subject: Contact Form
name: Mark 
email: sendersemail@gmail.com 
phone_number: 12345
message: hi again

该表单过去工作时没有任何问题,也没有任何更改。

服务器php更新是否会导致我的代码现在工作不正确?

我所希望做的就是能够回复发件人,而不必删除第二封电子邮件。发件人的电子邮件地址是否在发件人字段中username@whm4.bargainhosts.co.uk

欢迎任何帮助。

感谢Mark

更新2015年11月8日1432小时

一个网站联系表被用来发送到php代码,我现在在下面提供了它。

<?php
    $email = $_POST['email'];
    $after = "http://www.website.co.uk/thankyou.htm";
    $oops = "http://www.website.co.uk/error.htm";

if (!isset($_POST['submit']) || $_SERVER['REQUEST_METHOD'] != "POST") {
    exit("<p>You did not press the submit button; this page should not be accessed directly.</p>");
  
    }if(isset($_POST['g-recaptcha-response'])){
          $captcha=$_POST['g-recaptcha-response'];
        }
        if(!$captcha){
          echo "<meta HTTP-EQUIV='"REFRESH'" content='"0; url=$oops'">";
          exit;
        }
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=##########secretcode#########&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
        if($response.success==false)
        {
          echo "<meta HTTP-EQUIV='"REFRESH'" content='"0; url=$oops'">";
        }else
        {
          echo "<meta HTTP-EQUIV='"REFRESH'" content='"0; url=$after'">";
        }
    
if( isset($_POST['submit'])) {
    
    
    $recipient = "myemail@gmail.com";
    $title = "Contact Form";
   
$message .= "name: {$_POST['name']} 'n";
    $message .= "email: {$_POST['email']} 'n";
    $message .= "phone_number: {$_POST['phone_number']} 'n";
    $message .= "their-message: {$_POST['their-message']} 'n";
$headers .= "Reply-To: $email";
 $headers .= "From: $email";
  
mail($recipient,$title,$message,$headers);
       
}
 
?>

这是网站上使用的代码

<div id="contact_form">
       <form name="form" id="ff" method="post" action="http://www.webwsite.co.uk/c/form2015.php">
         <legend>Please help us by completing all fields</legend>
         <br>
         <label> <span>Name*:</span><br>
           <input type="text" placeholder="Please enter your name" name="name" id="name" required>
         </label>
         <label> <span>Email*:</span><br>
           <input type="email" placeholder="youremail@gmail.com" name="email" id="email" required>
         </label>
         <label> <span>Phone:</span><br>
           <input type="phone_number" placeholder="Please enter your phone" name="phone_number" id="phone_number">
         </label>
         <label> <span>Message*:</span><br>
           <textarea name="their-message" rows="5" required id="their-message" placeholder="Please enter your message"></textarea>
         </label>
         <div class="g-recaptcha" data-sitekey="################################################"></div>
         <br />
         <input name="Reset" id="reset" type="reset" class="reset" value="Reset" />
         <input name="submit" type="submit" class="submit"  value="Send" />
       </form>
     </div>   

以下内容可能写在两行上,但实际上会将电子邮件地址连接到上一个电子邮件地址。

$headers = "From: $email";  
$headers .= " $email";/* try commenting out this line */

如所示

From: myemail@gmail.com myemail@gmail.com [mailto:myemail@gmail.com myemail@gmail.com]

在下面的代码中,您将覆盖第二行的头变量,因为您没有连接字符串。

 $headers .= "Reply-To: $email";
 $headers = "From: $email";

尝试将其更改为:

 $headers .= "Reply-To: $email";
 $headers .= "From: $email";

根据你的原作,因为苏格兰正在下雨,我很无聊,所以我写了这篇文章,我希望它能有所帮助。我认为其中一个问题是标头中使用的行结尾,正如下面的评论中所指出的,在访问captcha检查的返回值时,语法似乎有点奇怪。


在我的测试中使用的表单页面上,我使用了:

head
----
<script type='text/javascript'>
    var key='<?php echo GOOGLE_RECAPTCHA_KEY; ?>';
    /* this is the public key */
    function verifyCaptcha(){
        grecaptcha.render( 'grc', {
            'sitekey'   :   key,
            'theme'     :   'light',
            'size'      :   'compact'
        });
    }
</script>
<script src='https://www.google.com/recaptcha/api.js?onload=verifyCaptcha&render=explicit' async defer></script>

body
----
<form name='mailtest' method='post' action='/test/target.php'>
    <h1>Google reCaptcha form mail test</h1>
    <input type='text' name='name' placeholder='Please enter your name' required />
    <input type='text' name='phone_number' placeholder='Please enter your phone' required />
    <input type='text' name='their-message' placeholder='Please enter your message' required />
    <input type='email' name='email' placeholder='Please enter your email address' required />
    <!-- empty placeholder for re-captcha -->
    <div id='grc'></div>
    <!-- A new form element will be created by the recaptcha if successful -->
    <!--
        g-recaptcha-response
    -->
    <input type="submit" value="Send email" />
</form>


form action script
------------------
<?php
    $after = "http://www.website.co.uk/thankyou.htm";
    $oops = "http://www.website.co.uk/error.htm";
    if( $_SERVER['REQUEST_METHOD']=='POST' ){

        /* Config: edit these to suit */
        $recipient='myemail@gmail.com';
        $subject='Contact Form Enquiry';
        $google_secret='abc-def-123-456xxxxxxxxx';


        /* Container in which to build message */
        $message=array();
        $headers=array();

        /* Fields of relevance to the email */
        $fields=array( 'email', 'submit', 'name', 'phone_number', 'their-message' );
        foreach( $fields as $field ){
            /* Assign as a variable variable */
            $$field=( isset( $_POST[ $field ] ) && !empty( $_POST[ $field ] ) ) ? trim( filter_input( INPUT_POST, $field, FILTER_SANITIZE_STRING ) ) : false;
            /* Add to message */
            if( $$field ) $message[]="{$field}: {$$field}";
        }
        /* Add elements to the headers array */
        $headers[]="From: {$email}";
        $headers[]="Reply-To: {$email}";
        /*
            These are pertinent to Outlook so could be set too
            --------------------------------------------------
            $headers[]="Importance: Normal";
            $headers[]="Sensitivity: Private";
            $headers[]="Priority: Urgent";
            $headers[]="Comments: an email from x";
            $headers[]="Keywords: x,y,z";
            $headers[]="Cc: user@example.com";
            $headers[]="Bcc: user@example.com";
        */

        /* Get submitted captcha image data */
        $captcha=isset( $_POST['g-recaptcha-response'] ) && !empty( $_POST['g-recaptcha-response'] ) ? $_POST['g-recaptcha-response'] : false;
        if( !!$captcha===false ) header( 'location: '.$oops.'?captcha=empty' );

        $response=file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=".$google_secret."&response=".trim( $captcha )."&remoteip=".$_SERVER['REMOTE_ADDR'] );
        /* decode */
        $response=json_decode( $response );
        /* The syntax you had seemed incorrect as it used a dot notation */
        if( $response->success ){
            /* To debug output and expected mail send parameters */
            exit("mail( '"$recipient'", '"$subject'", '"".implode( PHP_EOL, $message )."'", '"".implode( "'r'n", $headers )."'" )");
            /* Send the mail*/
            $res=@mail( $recipient, $subject, implode( "'n", $message ), implode( "'r'n", $headers ) );
            /* Redirect based upon mail sending success / failure */
            if( $res ) header( 'location: '.$after.'?mailsent=true' );
            else header( 'location: '.$oops.'?mailsent=false' );
        } else {
            /* Get the reason straight from the horses mouth */
            $reason=implode('_',$response->{'error-codes'});
            /* Redirect because capture failed */
            header( 'location: '.$oops.'?captcha=failed&reason='.$reason );
        }

    } else {
        /* Redirect - incorrect method */
        header( 'location: '.$oops.'?method=bad' ); 
    }
?>

成功验证并提交表单后,调试的输出为:

邮件("myemail@gmail.com","联系表格查询","电子邮件:joe.bloggs@example.com姓名:joe bloggs电话号码:0141 3533789他们的留言:你好,我需要你的帮助。。。再见,谢谢所有的鱼","来自:joe.bloggs@example.com答复:joe.bloggs@example.com")


示例输出没有显示的是行结尾为'r'n。顺便说一句,我假设url www.website.co.uk只是作为一个例子~就像example.com一样?如果没有,则表单的操作中存在拼写错误。