Php 有没有办法回复用户提供的电子邮件地址?

Php 有没有办法回复用户提供的电子邮件地址?,php,phpmailer,reply,Php,Phpmailer,Reply,我开始在我的网站上使用PHPMailer来建立一个联系表单(用户->我自己的电子邮件帐户)。电子邮件发送过程看起来一切正常,但当我想回复用户的电子邮件时,我面临一个问题 似乎从我的网站发送电子邮件的电子邮件地址是我的,通过SMTP->进行配置,我对此很满意 我为setFrom和addReplyTo方法定义了用户的电子邮件地址作为参数,以便能够从Gmail回复他的电子邮件,并且我的答案会发送到提供的电子邮件地址 然而,当我点击Gmail上的“回复”时,用户和我都收到了我的回复 我想我真的错过了一些

我开始在我的网站上使用PHPMailer来建立一个联系表单(用户->我自己的电子邮件帐户)。电子邮件发送过程看起来一切正常,但当我想回复用户的电子邮件时,我面临一个问题

似乎从我的网站发送电子邮件的电子邮件地址是我的,通过SMTP->进行配置,我对此很满意

我为setFromaddReplyTo方法定义了用户的电子邮件地址作为参数,以便能够从Gmail回复他的电子邮件,并且我的答案会发送到提供的电子邮件地址

然而,当我点击Gmail上的“回复”时,用户和我都收到了我的回复

我想我真的错过了一些东西,并且/或者误解了上面这些方法的目的

如前所述,我试图将addReplyTo放在setFrom上方,但看起来没有任何变化

我有点纠结于我还能做什么,我现在只使用了4个月的PHP,有些东西仍然没有找到,特别是关于这个问题

//class Mail

public function sendMail ()
{
    //Instantiation and passing "true" enables exceptions
    $mail = new PHPMailer(true);

    $msg = utf8_encode(wordwrap($this->message, 70, "\r\n"));

    try {
        //Server settings
        $mail->SMTPDebug = 0;
        $mail->isSMTP();
        $mail->Host = 'smtp.gmail.com';
        $mail->SMTPAuth = true;
        $mail->Username = 'my_email_address@gmail.com';
        $mail->Password = 'password';
        $mail->SMTPSecure = 'ssl';
        $mail->Port = 465;

        //Recipients
        //Jon Doe <my_email_address@gmail.com(?)>
        $mail->setFrom($this->mail, $this->first_name . ' ' . $this->last_name);
        //User's email address
        $mail->addReplyTo($this->mail);
        $mail->addAddress('my_email_address+ALIAS@gmail.com');


        // Content
        $mail->isHTML(true);
        //contact@domain.com : Jon Doe
        $mail->Subject = 'contact@domain.com : ' . $this->first_name . ' ' . $this->last_name;
        $mail->Body = $msg;
        $mail->AltBody = $msg;
        $mail->send();

    } catch (Exception $e) {
        //False need for my contact.php webpage if email cannot be sent 
        if (!empty($e->getMessage())) {
            $_POST['success'] = false;
       }
    }
}



//contact.php

if (!empty($_POST['last_name']) && !empty($_POST['first_name']) && !empty($_POST['mail']) && !empty($_POST['message']) && isset($_POST['g-recaptcha-response'])) {
    $first_name = htmlentities($_POST['first_name']);
    $last_name = htmlentities($_POST['last_name']);
    $mail = htmlentities($_POST['mail']);
    $message = htmlentities($_POST['message']);

    $contact = new Contact($first_name, $last_name, $mail, $message);  

    //Checking if everything's fine about form submission
    if ($contact->isBool()) {
        $mail = new Mail($contact);
        $mail->sendMail();

        //If something's wrong with the mailing process 
        if (isset($_POST['success'])) {
            //Just some text to display to inform the user
            $error_email['email_sent'] = "Foo";
        } else {
            //Just some text to display to inform the user
            $success = "Bar";
        }   
    } else {
        $errors = $contact->getErrors();   
    }
}
//类邮件
公共函数sendMail()
{
//实例化并传递“true”可启用异常
$mail=新的PHPMailer(true);
$msg=utf8_编码(wordwrap($this->message,70,“\r\n”);
试一试{
//服务器设置
$mail->SMTPDebug=0;
$mail->isSMTP();
$mail->Host='smtp.gmail.com';
$mail->SMTPAuth=true;
$mail->Username='我的电子邮件_address@gmail.com';
$mail->Password='Password';
$mail->SMTPSecure='ssl';
$mail->Port=465;
//接受者
//乔恩·多伊
$mail->setFrom($this->mail,$this->first\u name.'.$this->last\u name);
//用户的电子邮件地址
$mail->addReplyTo($this->mail);
$mail->addAddress('我的电子邮件地址'+ALIAS@gmail.com');
//内容
$mail->isHTML(true);
//contact@domain.com:乔恩·多伊
$mail->Subject=contact@domain.com:“.$this->first\u name.”.$this->last\u name;
$mail->Body=$msg;
$mail->AltBody=$msg;
$mail->send();
}捕获(例外$e){
//如果无法发送电子邮件,则不需要my contact.php网页
如果(!empty($e->getMessage())){
$\u POST['success']=false;
}
}
}
//contact.php
如果(!empty($_POST['last_name'])和($_POST['first_name'])和($_POST['mail'])和($_POST['message'])和&isset($_POST['g-recaptcha-response']){
$first_name=htmlentities($_POST['first_name']);
$last_name=htmlentities($_POST['last_name']);
$mail=htmlentities($_POST['mail']);
$message=htmlentities($_POST['message']);
$contact=新联系人($first\u name、$last\u name、$mail、$message);
//检查表单提交是否一切正常
如果($contact->isBool()){
$mail=新邮件($contact);
$mail->sendMail();
//如果邮寄过程出现问题
如果(isset($_POST['success'])){
//只是显示一些文本来通知用户
$error\u email['email\u sent']=“Foo”;
}否则{
//只是显示一些文本来通知用户
$success=“Bar”;
}   
}否则{
$errors=$contact->getErrors();
}
}
下面是我的Gmail帐户中关于邮件信息的屏幕截图:

我想从我的Gmail帐户回复用户的电子邮件,并希望他是唯一一个收到我回复的人。欢迎任何建议

编辑:
经过今天的多次尝试,当我点击Gmail上的“回复”按钮时,似乎只有我一个人收到了答案。用户没有收到任何信息…

回复地址应放在设置发件人地址之前。请参见下面的示例:

$mail->ClearReplyTos();
$mail->addReplyTo(yourreplytomailid, 'Name');
$mail->AddReplyTo('replyto@email.com', 'Reply to name');
$mail->SetFrom('mailbox@email.com', 'Mailbox name');
多亏了,我已经解决了我的问题

如果“发件人”地址与“收件人”地址相同,或者在GMail设置中配置为“发送方式…”帐户之一,GMail将回复“收件人”地址,而不是回复“收件人”地址。一个简单的解决方法是指定一个非Gmail“发件人”地址

=>这完全是我所做的。将电子邮件从我的Gmail帐户发送到我的Gmail帐户是问题所在,因此我更改了以下内容:

//Jon Doe <my_email_address@gmail.com(?)>
$mail->setFrom($this->mail, $this->first_name . ' ' . $this->last_name);

//User's email address
$mail->addReplyTo($this->mail);

$mail->addAddress('my_email_address+ALIAS@gmail.com')
然后,我使用了Gmail以外的另一个SMTP服务器提供商,并对我的\u地址进行了重定向_email@NOT_GMAIL.com我的地址_email@gmail.com


现在一切都正常了。

你能在gist/pastebin中发布原始电子邮件标题,让我们看看问题出在哪里吗?当然,这里是:它看起来无法解决问题。回复地址需要在发件人地址之前添加:正如我在第一篇帖子中提到的,我尝试过这个方法,但没有改变任何东西:(您是否尝试过:$mail->AddReplyTo('replyto@email.com“,”回复姓名“;$mail->AddAddress('user@email.com“,”用户名);$mail->SetFrom('mailbox@email.com“,”邮箱名“;是的,我有,但显然还是同一个问题:(
//user's_email_address@something.com
$mail->addReplyTo($this->mail);

$mail->addAddress('my_email_address@NOT_GMAIL.com');

$mail->setFrom('my_email_address@NOT_GMAIL.com');