Hello, there was a problem with the letters that are returned if they were not delivered for some reason.

They need to be redirected to another email.
But the return-path header does not work.

I set my return-path , but, after sending, a letter arrives not in the box that is specified, but on the one from which it was sent, and my assigned email is erased in the letter.

An example of my code:

  $body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; $body .= '<html xmlns="http://www.w3.org/1999/xhtml">'; $body .= '<head>'; $body .= '<meta http-equiv="Content-Type" content="text/html; charset="' . Yii::$app->charset . '" />'; $body .= '<title></title>'; $body .= '</head>'; $body .= '<body>'; $body .= 'Test Message'; $body .= '</body>'; $body .= '</html>'; Yii::$app->mailer->useTransport('system')->compose() ->setFrom(['example@some.com' => 'example.com']) ->setReturnPath('bounced@some.com') ->addHeader('Reply-To', 'bounced@some.com') ->setTo('example2@some.com') ->setSubject('TEST MESSAGE') ->setHtmlBody($body) ->send(); 

To send mail using swiftmailer .

I Google already for a long time, the installation of any other headers did not lead to a positive result.

Maybe you have any options?

Headers that come back:

 Return-path: <example@some.com> Envelope-to: example2@some.com Delivery-date: Thu, 13 Oct 2016 17:42:28 +0300 Received: from some.com ([159.203.33.129]) by site.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84) (envelope-from <example@some.com>) id 1buhDH-0002DI-S0 for example2@some.com; Thu, 13 Oct 2016 17:42:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=site.com; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:To:From:Subject:Date:Message-ID; bh=TJEj83H/pPguf4pMS+4FcdmBzKkRiY+DeLg2oWD2/iQ=; b=kA3lrgCRo3Wqr6ky6JVhytV6m/Qx1L3NXFybgPWxyBE5bEqqFGWgOEJQd5O5sppbDnfWB780Hz0FKA8OiiT3IrbzvohHzjRf5SD/IYFz6IaGaN9jwVTojo5jFfBv8t6lv9KprH6MFQEqKJ8bqKNGp3HYIWlr6DXQAEAAl6CogqY=; Received: from [178.74.217.102] (helo=[127.0.0.1]) by site.com with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from <example@some.com>) id 1buhDG-0001i4-Su for example2@some.com; Thu, 13 Oct 2016 10:42:27 -0400 Message-ID: <34cb7242e992226ad1d1f74b821c325f@swift.generated> Date: Thu, 13 Oct 2016 10:42:25 -0400 Subject: TEST MESSAGE From: "Example.com" <example@some.com> To: example2@some.com MIME-Version: 1.0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable ; Return-path: <example@some.com> Envelope-to: example2@some.com Delivery-date: Thu, 13 Oct 2016 17:42:28 +0300 Received: from some.com ([159.203.33.129]) by site.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84) (envelope-from <example@some.com>) id 1buhDH-0002DI-S0 for example2@some.com; Thu, 13 Oct 2016 17:42:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=site.com; s=dkim; h=Content-Transfer-Encoding:Content-Type:MIME-Version:To:From:Subject:Date:Message-ID; bh=TJEj83H/pPguf4pMS+4FcdmBzKkRiY+DeLg2oWD2/iQ=; b=kA3lrgCRo3Wqr6ky6JVhytV6m/Qx1L3NXFybgPWxyBE5bEqqFGWgOEJQd5O5sppbDnfWB780Hz0FKA8OiiT3IrbzvohHzjRf5SD/IYFz6IaGaN9jwVTojo5jFfBv8t6lv9KprH6MFQEqKJ8bqKNGp3HYIWlr6DXQAEAAl6CogqY=; Received: from [178.74.217.102] (helo=[127.0.0.1]) by site.com with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from <example@some.com>) id 1buhDG-0001i4-Su for example2@some.com; Thu, 13 Oct 2016 10:42:27 -0400 Message-ID: <34cb7242e992226ad1d1f74b821c325f@swift.generated> Date: Thu, 13 Oct 2016 10:42:25 -0400 Subject: TEST MESSAGE From: "Example.com" <example@some.com> To: example2@some.com MIME-Version: 1.0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable 

UDP
To send emails use mailjet .

  • > I set my return-path, but after sending, a letter arrives not in the box that is specified, but on the one from which it was sent, and my assigned email is erased in the letter. This is standard behavior. Bounce is set by the SMTP "MAIL FROM" command. What kind of transport do you use? Sendmail and SMTP should take this value from setReturnPath. - Vladislav Ross
  • @VladislavRoss, using SMTP. Well, the return-path seems to be taken from there, but I see a completely different picture. You see that in the settings I still prescribe this path. - Bogdan Gudyma
  • one
    Since this is such a non-trivial problem, then I would get into the class code of the SMTP transport and logged that he writes to the port. If he writes MAIL FROM bounced@some.com, then everything is correct, and this is already the server willfully send bounce to the wrong place. - Vladislav Ross
  • @VladislavRoss, I will try to secure this case - Bogdan Gudyma
  • Tell me what you finally figured out - Vladislav Ross

1 answer 1

Have you tried setSender() instead of setReturnPath ?

Similar problems arose in these people:

https://github.com/swiftmailer/swiftmailer/issues/384

https://stackoverflow.com/questions/26762802/phpmailer-bounced-mails-not-getting-bounced-right/26765956#26765956

  • pointed out this leader, but still the same - Bogdan Gudyma