Search code examples
phpphpmailer

phpmailer: Reply using only "Reply To" address


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 from the mailbox address and then I have added a reply to address for where I want the replies to go to:

$mail = new PHPMailer();

$mail->IsSMTP();
$mail->SMTPAuth   = true;
$mail->SMTPSecure = 'tsl';
$mail->SMTPDebug  = 1;
$mail->Host       = EMAIL_HOST;
$mail->Port       = EMAIL_PORT;
$mail->Username   = EMAIL_USER;
$mail->Password   = EMAIL_PASS;

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

The emails send successfully and seem to get through the spam filters ok, but when I press reply it includes both the mailbox account and the reply to account.

Is this what is meant to happen? I only want the reply to address to appear when you press reply. Is this even possible?


Edit:

Looking at the email headers it seems like the from address is getting included in the reply to field. I have no idea why!

Date: Tue, 1 May 2012 11:16:25 +0100
To: User name <user@email.com>
From: Mailbox name <mailbox@email.com>
Reply-to: Mailbox name <mailbox@email.com>, Reply to name <replyto@email.com
Subject: Email subject
Message-ID: <54c530c0d1f3ff33fc87c4c41c2c9ffd@localhost>
X-Priority: 3
X-Mailer: PHPMailer 5.1 (phpmailer.sourceforge.net)
MIME-Version: 1.0
Content-Type: multipart/alternative;
     boundary="b1_54c530c0d1f3ff33fc87c4c41c2c9ffd"

--b1_54c530c0d1f3ff33fc87c4c41c2c9ffd
Content-Type: text/plain; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit

Solution

  • 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');