SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    From header not working

    When I upload an autoresponder the "from" doesn't work. It comes back as CGI-Mailer, rather than what I specified.

    What is causing this?

    The code is:
    PHP Code:
    //autoresponder
        
    $myname "Company";
        
    $subject "Thank you for contacting us";
        
    $body "Thank you for contacting us.  We will answer your query within the next 48 hours.\n\nRegards.";
        
    $headers "Content-Type: text/plain; charset=us-ascii
        From: 
    $myname
        X-Mailer: PHP"
    ;
        
        
    mail($email ,$subject $body $headers); 
    The script is on https if that makes any difference.

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $headers "Content-Type: text/plain; charset=us-ascii\n"//<-- \n new line
    $headers .= "From: ".$email."\n"//<-- \n new line
    $headers .=  "X-Mailer: PHP/" phpversion(); 
    You are missing new lines.
    -- Jelena --

  3. #3
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jelena. I'll give that a go. Much appreciated.

  4. #4
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Almost worked perfectly.

    When the email comes in it says it is from "company@"

    Where is the @ coming from?

  5. #5
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because as per spec the From: header field MUST be an e-mail address. Whatever client you're reading the message in (or perhaps a server somewhere along the way, perhaps even sendmail itself) is trying to force that field to comply.

    If you want to use a human-readable name, then you need a format like:
    PHP Code:
    $myname '"Company" <blah@example.com>'
    PHP questions? RTFM
    MySQL questions? RTFM

  6. #6
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Spot on kromey. Worked a treat. Thank you very much.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •