PHP Classes

Return Path

Recommend this page to a friend!

      SMTP E-mail sending class  >  All threads  >  Return Path  >  (Un) Subscribe thread alerts  
Subject:Return Path
Summary:Setting the return path (especially for bouncing mails)
Date:2009-07-03 13:19:24
Update:2011-11-11 06:09:47

  1. Return Path   Reply   Report abuse  
Ron - 2009-07-03 13:19:24
Hi Manuel,
thanks for your great classes!

I was wondering, if there is a way of setting the return path in the smtp class, especially with respect to bouncing mails.


  2. Re: Return Path   Reply   Report abuse  
Manuel Lemos - 2009-07-03 22:49:59 - In reply to message 1 from Ron
In SMTP the return path address is the sender e-mail address passed to the FROM command, which is not necessarily the same as in the From header.

Anyway, it is more recommended that you use the SMTP class in conjunction with the MIME message class, as it knows better how to compose and send messages compliant with the Internet e-mail standards.

  3. Re: Return Path   Reply   Report abuse  
ced - 2011-11-07 15:20:31 - In reply to message 2 from Manuel Lemos

I use smtp class with sasl class and mime message class.

I have a strange header ...

If I set the debug mode, I see that :

S 235 2.7.0 Authentication successful
Errors-To: =?ISO-8859-1?q?Maria=2C_Clairvoyant=2C_Universal_Medium?= <>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="aa357aa4ff61f316723b3e87eb00769c"
Date: Mon, 07 Nov 2011 10:10:31 EST
Message-ID: <>

And in the email header :

From: =?ISO-8859-1?q?Maria=2C_Clairvoyant=2C_Universal_Medium?=
Message-ID: <>

I have 2 questions :

1) Why in the debug mode, the FROM field is equal to the Return-Path field ?

2) How can I modify the message ID to have the smtp hostname and not the Return-Path address ?

Thanks in advance for your response



  4. Re: Return Path   Reply   Report abuse  
Manuel Lemos - 2011-11-08 01:04:16 - In reply to message 3 from ced
SMTP servers do no look at the message headers, so the Return-path headers and others are irrelevant. In the SMTP protocol, the address passed by the FROM command is also to where and bounced messages will go.

Keep in mind that the SMTP FROM command is totally unrelated to the From: header, so they may point to the same address or not. This is what allows bounces to go to an address different from the sender address set in the From: header.

Setting the Return-Path: header to your bounce address is a just a convention invented by me for the MIME message class. Coincidentally other e-mail classes also adopted it.

If you want the class to not set the Message-ID header automatically, just set the class variable auto_message_id to 0.

  5. Re: Return Path   Reply   Report abuse  
ced - 2011-11-08 08:59:14 - In reply to message 4 from Manuel Lemos
Hi Manuel,

Thank you for your fast response.

I try the auto_message_id to 0 today.

Many thanks for your great classes !


  6. Re: Return Path   Reply   Report abuse  
ced - 2011-11-09 12:49:02 - In reply to message 4 from Manuel Lemos
Hi Manuel,

Just a question.
If I specify a return-path on the header, it will be send on the MAIL FROM.
Because your function SendMessageHeaders take it at line 713 :
if(!$this->smtp->MailFrom(count($return_path) ? Key($return_path) : Key($from)))

So I want my return path be :
and the MAIL FROM :

Is it possible ??

thanks in advance

  7. Re: Return Path   Reply   Report abuse  
Manuel Lemos - 2011-11-09 19:52:54 - In reply to message 6 from ced
Sure, just try it.

  8. Re: Return Path   Reply   Report abuse  
ced - 2011-11-10 09:12:30 - In reply to message 7 from Manuel Lemos
I tried it but it don't work ...

When I specify a return-path address as "", the MAIL FROM smtp command take this address : MAIL FROM:
but my $from_address variable is ...

I think it's because on your smtp_message class, in SendMessageHeaders() function, you write that :

if(!$this->smtp->MailFrom(count($return_path) ? Key($return_path) : Key($from)))

So I changed this line with :


And with this modification, MAIL FROM is good : MAIL FROM:

But now, the return path is equal to the MAIL FROM ...

I think it's a bug or a configuration problem.

Here is my configuration :


And the header construct part :

$email_message->SetEncodedEmailHeader("To",$to_address,$to_name, 'UTF-8');
$email_message->SetEncodedEmailHeader("From",$from_address,$from_name, 'UTF-8');
$email_message->SetEncodedEmailHeader("Reply-To",$reply_address,$reply_name, 'UTF-8');

Thank you very much for your help Manuel.


  9. Re: Return Path   Reply   Report abuse  
Manuel Lemos - 2011-11-11 06:09:47 - In reply to message 8 from ced
No, I think you are confused. The class works as intended. If you specify the Return-path header, the SMTP FROM command uses that. That command is the way to tell the SMTP server where the message should be returned in case it bounces.

The SMTP FROM command has nothing to do with the From: header. The class only uses the address in the From header if you do not specify the Return-Path: header.

In any case the From: header will always exhibit what you set it to regardless what was passed to the SMTP FROM command.