Want something other than Nobody in the from field

Discussion in 'PHP' started by Colbyt, Sep 7, 2006.

  1. #1
    I have this simple script that seems to work fine except that it always shows Nobody as the sender when it is received by Outhouse Express.

    Inside the body of the email all information is present.

    I would like to accomplish this one of of two ways:
    1. First choice would be for it to tag it automatically with mydomain/subdomain

    2. Second choice would that I enter the domain manually into each instance of the script.

    Only a snippet shown. Line breaks added for readablity.
    Last question any known security issues with any of the above?
     
    Colbyt, Sep 7, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just add From in the same format as the $to variable.
     
    mad4, Sep 7, 2006 IP
  3. wmburg

    wmburg Active Member

    Messages:
    300
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    You need from in the email headers.

    $from_domain = $_SERVER["HTTP_HOST"];
    
    if (substr($from_domain,0,4) == "www.") 
      $from_domain = substr($from_domain,4);
    
    $from_name = "Your Name";
    $from_email = "email@$from_domain";
    
    mail ($to, $subject, "A message from $name at $email:\r\n $message \r\n\r\n$name's remote host is $REMOTE_HOST and $name's specified hostname is $VIRTUAL_REMOTE_HOST. \r\nThe sender's IP Address is $REMOTE_ADDR and the sender's \r\nUser-Agent string is $HTTP_USER_AGENT.", "From: $from_name <$from_email>\r\n" ) or print "An unknown error occured.<br>";
    PHP:
     
    wmburg, Sep 7, 2006 IP
  4. wmburg

    wmburg Active Member

    Messages:
    300
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Global variables ($REMOTE_ADDR, $HTTP_USER_AGENT) = bad

    http://us2.php.net/manual/en/security.globals.php

    $_SERVER["REMOTE_ADDR"]
    $_SERVER["HTTP_USER_AGENT"]
     
    wmburg, Sep 7, 2006 IP