Welcome Guest, Not a member yet? Register   Sign In
Email Class - Not able to set Return-Path header
#1

[eluser]MeanStudios[/eluser]
Greetings,

I'm trying to send out an email where I change the 'Return-Path' header to something other than the 'From' email address but I am having no luck. In the libraries/Email.php file I've commented out line 201:
Code:
$this->_set_header('Return-Path', '<'.$from.'>');
and then in my controller I did:
Code:
$this->email->_set_header('Return-Path', '<[email protected]>');
but this did not work. It's still setting the return path to the 'From' address hence sending bounce-back emails to that address instead of the address I'm trying to nominate for the 'Return-Path'.

Here is the output:
Code:
220 mail.alpha.net.au ESMTP AlphaMailServices MTA: Wed, 8 Jul 2009 17:00:05 +1000

hello: 250-mail.alpha.net.au Hello gateway2.alpha.net.au [203.41.44.5], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE 15000000
250-DSN
250-ETRN
250-AUTH LOGIN PLAIN
250-DELIVERBY
250 HELP

from: 250 2.1.0 ... Sender ok

to: 250 2.1.5 ... Recipient ok

data: 354 Enter mail, end with "." on a line by itself

250 2.0.0 n68705NG002766 Message accepted for delivery

quit: 221 2.0.0 mail.alpha.net.au closing connection

Your message has been successfully sent using the following protocol: smtp

User-Agent: CodeIgniter
Date: Wed, 8 Jul 2009 17:00:03 +1000
From: "Cody Lundquist"
Reply-To: "Cody Lundquist"
To: cody@4
Return-Path:
Subject: =?utf-8?Q?df?=
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0


Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

<p>sdf</p>
As you can see there, the Return-Path is blank. Although if I uncomment out the line I said above and remove my '_set_header()' method it's still blank. Which leaves me to believe that CodeIgniter is not even sending it in the first place and the mail server is using the 'From' address since 'Return-Path' is blank. If I do something like
Code:
$this->email->_set_header('Custom-Header', '<[email protected]>');
it's still blank when using
Code:
echo $this->email->print_debugger();
but the bounceback I receive from the server has that 'Custom-Header' set correctly.

So this is very weird....
#2

[eluser]MeanStudios[/eluser]
Update
The 'Return-Path' is not blank when using the print_debugger(); You just have to look at the src of the document to see it. For some reason FireFox blanks it out heh. So ya, it's being sent, but the mail server still thinks that it's the 'From' address ><.
#3

[eluser]sophistry[/eluser]
not sure if you solved the problem...?

the reason you can't see the email address is because the browser thinks that it is a "tag" because it is inside tag delimiters < and >.

i've seen mail servers manipulate headers before. if your return-path is being changed, it may be a policy of the ISP to force the From and Return-Path header fields to match; sometimes spammers will spoof a Return-Path address to get an intentional "bounce" message that gets "returned" to the spoofed address. It's a trick they use to get regular mailservers (i.e., not open relays) to resend spam.

cheers.
#4

[eluser]MeanStudios[/eluser]
Sophistry,

Ya, I figured that out once I looked at the source code heh Smile.

As for the return-path thing, no, I never did get it figured out. I decided to use PHPMailer instead as all you have to do with that Email Class is:
Code:
$email->Sender = '[email protected]';
and it will work just fine. With the same ISP and everything.

I don't think the CI Email class is setup right to handle changing the Return-Path, there are some lines that are hardcoded to use the 'From' address in those instances and I didn't feel like making changes to the Email.php file since I have that folder being updated by the CI public SVN.

Thanks for your response though!
#5

[eluser]sophistry[/eluser]
MeanStudios... you are correct about the hard-coding of Return-Path so that it equals the From header. That's lame, but there may be a reason the CI devs did it that way.

In any case, it can't be a very good reason because a competent developer should be able to set any header they want to in a proper email class.

I'd suggest filing a bug report if you want to or if you want to move on with your life and stick with PHPMailer, that's fine too! I think SwiftMailer swiftmailer.org looks pretty good.

cheers.
#6

[eluser]roguemonk[/eluser]
I'm a little late to this party.

It actually sucks that this isn't working, but I wonder if it isn't the email server making the changes. What protocols is phpmailer using? I tried sendmail and smtp with no luck. Didn't try mail.

In the interim, a quick solution might be to set the from email to your Return-Path and make reply_to your preferred "human-readable" email (I'm assuming most people will just hit 'reply' on an email). In tests, this seems to work, but I haven't tested across multiple clients.

It doesn't fix the underlying problem, but might allow us to use the email class for simpler projects requiring this.

Thoughts?

--Dave
#7

[eluser]MeanStudios[/eluser]
Thanks for the suggestion Dave but I just went with using phpmailer instead. We used to use your method lined out above but it's a bit unprofessional for our clients to be sending out emails to their clients with our VERP email address out there for everyone to see. I would rather have it buried in the email's header Wink.
#8

[eluser]roguemonk[/eluser]
Got it!

Line 1540 (CI1.7.1) of the Email class (this is for sendmail... I believe it's similar for mail. Not sure about smtp):

$fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');

The -f flag sets the Return-Path.

Using this example switched the Return-Path for me:

$fp = @popen($this->mailpath . " -oi -f "."[email protected]"." -t", 'w');

In a real application, I would keep a variable, but make it point to _headers['Return-Path']. No angle brackets here.

Can someone confirm this for me.

--Dave
#9

[eluser]sophistry[/eluser]
[quote author="roguemonk" date="1249984805"]In a real application, I would keep a variable, but make it point to _headers['Return-Path']. No angle brackets here.[/quote]

hi roguemonk,

thanks for sussing that. even with the -f switch, some sendmail servers will still be configured to set their own Return-Path.

just a note about the suggestion to modify the code and use the _headers['Return-Path'] Email class property... as the title of this thread indicates, that header is set to the same value as the From: header.

BTW, on careful reflection, i think separating From and Return-Path is a feature rather than a bug. i know i suggested reporting it as a bug! But, it really is an <em>upgrade</em> to the Email class that would make it more flexible rather than a bug that makes it unusable.

cheers.

phew, 1000 posts!
#10

[eluser]Unknown[/eluser]
I was having a similar problem with emails being rejected. I fixed it by removing the space after the -f switch on line 1519 of Email.php. There's a comment directly above that line that says they added the space because some servers seem to require it. It would seem my host (rackspacecloud) requires there not be a space after the switch and the email address. Hope this helps someone else




Theme © iAndrew 2016 - Forum software by © MyBB