phpmailer: Reply using only “Reply To” address

前端 未结 2 992
北海茫月
北海茫月 2020-11-29 23:30

I\'m using phpmailer on my website and to help with spam issues I have created a mailbox to send these emails from (using SMTP).

I have set the emails to come

相关标签:
2条回答
  • 2020-11-30 00:18

    I have found the answer to this, and it is annoyingly/frustratingly simple! Basically the reply to addresses needed to be added before the from address as such:

    $mail->addReplyTo('replyto@email.com', 'Reply to name');
    $mail->SetFrom('mailbox@email.com', 'Mailbox name');
    

    Looking at the phpmailer code in more detail this is the offending line:

    public function SetFrom($address, $name = '',$auto=1) {
       $address = trim($address);
       $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
       if (!self::ValidateAddress($address)) {
         $this->SetError($this->Lang('invalid_address').': '. $address);
         if ($this->exceptions) {
           throw new phpmailerException($this->Lang('invalid_address').': '.$address);
         }
         echo $this->Lang('invalid_address').': '.$address;
         return false;
       }
       $this->From = $address;
       $this->FromName = $name;
       if ($auto) {
          if (empty($this->ReplyTo)) {
             $this->AddAnAddress('ReplyTo', $address, $name);
          }
          if (empty($this->Sender)) {
             $this->Sender = $address;
          }
       }
       return true;
    }
    

    Specifically this line:

    if (empty($this->ReplyTo)) {
       $this->AddAnAddress('ReplyTo', $address, $name);
    }
    

    Thanks for your help everyone!

    0 讨论(0)
  • 2020-11-30 00:28

    At least in the current versions of PHPMailers, there's a function clearReplyTos() to empty the reply-to array.

        $mail->ClearReplyTos();
        $mail->addReplyTo(example@example.com, 'EXAMPLE');
    
    0 讨论(0)
提交回复
热议问题