PHPMailer Return Path in MailSend function incorrect

185 views
Skip to first unread message

Oli Griffiths

unread,
Oct 17, 2009, 5:08:34 AM10/17/09
to joomla-de...@googlegroups.com
Hi All,

We’re using Jmail to send out some emails, and we’ve recently moved a site to a new server and now the return path header that we manually set in our script is being overwritten by after the mail() function is invoked and being replaced with apa...@thedomain.com which is bad. Now I know this issue is an enviroment issue however, as a developer of an app we have to cater for different server environments, so I need to make the component work in all cases (this is all for bounce management btw, need to se the return path to bou...@thedomain.com).

I know this issue isnt a direct Joomla issue, however, I think I have uncovered a bug in phpmailer that could be solved by overriding the MailSend function of PHPMailer in the Jmail class. The function that sends mail using the php mail() function in PHPMailer appears to have a bug in it where its incorrectly detecting safe_mode. The code in question is as follows: (line 472 – 491 in phpmailer.php)



        
$params = sprintf("-oi -f %s", $this->Sender);
   if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
     $old_from = ini_get('sendmail_from');
     ini_set('sendmail_from', $this->Sender);
     if ($this->SingleTo === true && count($toArr) > 1) {
       foreach ($toArr as $key => $val) {
         $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
       }
     } else {
       $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
     }
   } else {
     if ($this->SingleTo === true && count($toArr) > 1) {
       foreach ($toArr as $key => $val) {
         $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
       }
     } else {
       $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
     }
   }

The issue I have with this is 2 fold:

  1. The line: if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) will always return false as ini_get(‘safe_mode’) always returns a 1 or 0 which has a string length of 1
  2. The line $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); is adding the –f parameter to mail() which is shouldn’t be due to the fact that $this->Sender is either not set or safe mode is not enabled (you cant specify additional params if safe mode is on). If either of those are false then you shouldn’t be specifying the params var.

Can any one confirm this as an issue? It would be fairly easy to fix by overriding the MailSend() function in the Jmail class.

Oli

Ian MacLennan

unread,
Oct 17, 2009, 11:22:23 AM10/17/09
to joomla-de...@googlegroups.com
The preferable scenario would be that you get it fixed upstream in phpmailer and then we can look at merging those fixes into our codebase.  Have you checked there to see if that bug has been filed?

Ian

Oli Griffiths

unread,
Oct 17, 2009, 1:17:57 PM10/17/09
to joomla-de...@googlegroups.com

I agree, and I'll submit a ticket to their big tracker, however I've seen several posts on google that talk about the same issue from v 2.0.3. I don't know what phpmailers response time is like, which is why I'm suggesting this as a temp patch until it gets fixed.

sankesolutions

unread,
Oct 19, 2009, 8:27:14 AM10/19/09
to Joomla! General Development
I recently came across this issue with core joomla emails,
particularly the contact form. Im glad someone has worked out where
the issue is. I believe the techs have done some kind of workaround.
Ours became a major issue as it would only relay mail that had the
servers domain as the return path, so no mail was going out.

I will follow this with interest.

Paul

On Oct 17, 6:17 pm, Oli Griffiths <o...@organic-development.com>
wrote:
> I agree, and I'll submit a ticket to their big tracker, however I've seen several posts on google that talk about the same issue from v 2.0.3. I don't know what phpmailers response time is like, which is why I'm suggesting this as a temp patch until it gets fixed.
>
>
>
>
>
>
> On 17 Oct 2009, at 16:22, "Ian MacLennan" <ian.ma...@joomla.org> wrote:
>
>
>
> The preferable scenario would be that you get it fixed upstream in phpmailer and then we can look at merging those fixes into our codebase.  Have you checked there to see if that bug has been filed?
> IanOn Sat, Oct 17, 2009 at 5:08 AM, Oli Griffiths<o...@organic-development.com>wrote:Hi All,
> We’re using Jmail to send out some emails, and we’ve recently moved a site to a new server and now the return path header that we manually set in our script is being overwritten by after the mail() function is invoked and being replaced witha...@thedomain.comwhich is bad. Now I know this issue is an enviroment issue however, as a developer of an app we have to cater for different server environments, so I need to make the component work in all cases (this is all for bounce management btw, need to se the return path tobo...@thedomain.com).
> I know this issue isnt a direct Joomla issue, however, I think I have uncovered a bug in phpmailer that could be solved by overriding the MailSend function of PHPMailer in the Jmail class. The function that sends mail using the php mail() function in PHPMailer appears to have a bug in it where its incorrectly detecting safe_mode. The code in question is as follows: (line 472 – 491 in phpmailer.php)
>         $params=sprintf("-oi -f %s",$this->Sender);   if($this->Sender!=''&&strlen(ini_get('safe_mode'))<1){     $old_from=ini_get('sendmail_from');     ini_set('sendmail_from',$this->Sender);     if($this->SingleTo===true&&count($toArr)>1){       foreach($toArras$key=>$val){         $rt=@mail($val,$this->EncodeHeader($this->SecureHeader($this->Subject)),$body,$header,$params);       }     }else{       $rt=@mail($to,$this->EncodeHeader($this->SecureHeader($this->Subject)),$body,$header,$params);     }   }else{     if($this->SingleTo===true&&count($toArr)>1){       foreach($toArras$key=>$val){         $rt=@mail($val,$this->EncodeHeader($this->SecureHeader($this->Subject)),$body,$header, $params);       }     }else{       $rt=@mail($to,$this->EncodeHeader($this->SecureHeader($this->Subject)),$body...
>
> read more »
Reply all
Reply to author
Forward
0 new messages