The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Setting Return Path and recevied from in php

Discussion in 'General Discussion' started by lloyd_tennison, Sep 23, 2005.

  1. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    Setting Return Path and received from in php

    I started having the username as the return address not the sender. I have both the sender and Return-path set, and am using phpsuexec. Unfortunately, I upgraded my OS to Fedora core 4 and CPanel came out with major update at about the same time - so I do not know which is killing it as it worked for a long time - a year or more.

    I used to just have the sender in - always worked. Now says the return path of the master user on that account - even if I out Return-path: (or Return-Path:) it now always overwrites as does the received from line. They both say the username for that domain.

    Headers set are:

    $headers .= "Return-Path: ".$emailfrom." <".$email.">\r\n";
    $headers .= "From: ".$emailfrom." <".$email.">\r\n";

    with the return path just added to see if would solve problem.

    Any thoughts as what may have changed. As far as I can tell, only phpsuexec deals with making sure the nobody is gone and not to force the sender.


    (The "from" works perfectly.)
     
    #1 lloyd_tennison, Sep 23, 2005
    Last edited: Sep 24, 2005
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    The Return-Path has to be in the format:

    That is:

    Return-Path: <me@mydomain.com>
     
  3. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    Chirpy:

    That has totally lost me as I have no idea where that quote is from or means or goes.

    It certainly does not seem to want to go into the

    $headers .=


    You really lost me this time. :confused:
     
  4. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Sorry :eek:

    The code line would be:

    $headers .= "Return-Path: <".$email.">\r\n";

    The section I posted was the RFC format for explaining the structure of email header fields, in this case from RFC2822:
    http://ietf.org/rfc/rfc2045.txt?number=2822
     
  5. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    Been there, done that. I tried that one before I tried the one posted (duplicate of the from line.)

    Does not do so.

    Still comes as the user at the server name - not even the domain name.

    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Return-Path: <".$email.">\r\n";
    $headers .= "From: ".$emailfrom." <".$email.">\r\n";
    $headers .= "X-Priority: 1\r\n";

    The from works fine - that's why I am so confused, especially since did work before OS and CPanel update as shown.
     
  6. sleddog

    sleddog Active Member

    Joined:
    Jun 13, 2004
    Messages:
    44
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Labrador, Canada
    (I'm sure that Chirpy can explain this better than me, but I'll give it a go...)

    PHP scripts called through a webpage are run as user nobody (unless you're running PHP as a CGI, which I don't think is the case here). So email sent by a PHP script is sent as the user nobody, and the return path is to the user nobody -- "nobody@servername.domain.tld".

    It is possible to change the return-path header in the email, but not every user can do that -- only trusted users are allow to set a different return-path header. The user "nobody" is, by default, not a trusted user, so attempts to change the return path fail.

    The solution is to make "nobody" a trusted user. You can do that by editing the exim configuration:

    - In WHM go to the exim configuration, advanced mode;
    - In the top-most editing box add this line:
    Code:
    trusted_users = nobody
    - save the configuration and ensure that exim is restarted.

    After that you will be able to change the return-path header from a script, provided you get the syntax right :)

    I don't know if there are any security implications to doing this -- there may well be. Comments appreciated.

    (Edit)... Reread the original post and see that you are indeed running as CGI (phpsuexec). Which means all the above is irrelevant, sorry.
     
    #6 sleddog, Sep 25, 2005
    Last edited: Sep 25, 2005
  7. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    Even when I uncheck
    in WHM, still no difference.

    Running suexec and phpsuexec - so I as understand all of the options selected - nobody could not run at all.
     
  8. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    As sleddog has said, and to vary it a little as you're using phpsuexec, try adding the following instead:

    trusted_users = *
     
  9. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    The User *is not allowed:

    Even when I specify the one user I am testing with the return path is still not set. I also added mail as a user to test with.) I saw something on using the -f variable, but I have not made that work either, in conjuction with the other headers.
     
  10. zella

    zella Member

    Joined:
    Aug 5, 2005
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    You can use the fifth parameter of the mail function like :

    mail (parm1, parm2, parm3, parm4, '-f your_return_address');

    As i'm sure this works fine.
     
Loading...

Share This Page