Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php mail() form - Changing The FROM email

    I've checked the php manual and I've tried a few things but can't figure it out..

    Right now when someone submits a mail form through my site - the FROM: address is this annoying username@123linhost.bb.blahblahblah.com path from my godaddy hosting.

    I'd like to change this to something simple and nice like...

    mail@MyDomain.com

    I've tried using headers (but evidently these don't do what I want)

    PHP Code:
        $headers "MIME-Version: 1.0\r\n"
       
    $headers .= "From: [email]mail@mydomain.com[/email]>\n"
       
    $headers .= "Reply-To: [email]info@mydomain.com[/email]\n"
       
    $headers .= "X-Priority: 2\n"
       
    $headers .= "X-MSMail-Priority: Normal\n"
       
    $headers .= "X-Mailer: PHP4\n"
       
    $headers .= "Content-type: text/html; charset=iso-8859-1" "\n"
    In the manual it talks about changing the sendmail_from = in my php.ini file but I can't get to this except through SSH which I know nothing about.

    Any other options?

    Thanks

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Your From: line headers look a little funky to me. Shouldn't it just be something like this?
    PHP Code:
    $headers "From: Display Name <username@domain.tld>\n"

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    yea

    yea I'd pulled that from a post a few months back.. changing it didn't do any good

  • #4
    New Coder
    Join Date
    Sep 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm willing to bet it's the way you're doing the newlines.

    I've had these strange problems on unix servers where (if there was more than 1 line in the header) the email address would be root@subdomain.domain.tld.

    Try changing them all to carriage returns (\r\n) and try putting the From above the MIME-Version...dunno if it'll work but it's worth a shot.

  • #5
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    A couple of things.

    First, change all your new lines (\n) to carriage return newlines (\r\n)

    Second, your header format should be

    "From: User Name<email@domain.com>\r\n"

    And third, for spam filters, you may need to use the -f option in the mail funciton

    example:

    mail(TO_ADDY, SUBJECT, MESSAGE, $headers, -f youremail@yourdomain.com);

  • #6
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, having the same problem
    PHP Code:
    $to $e;
                
    $subject "One more step";
                
    $message "Hello, <br><br>";
                
    $message .= "Just one more step and you will be on your way to joining <a href=\"http://www.webiste.com\" target=\"_blank\">Website</a><br><br>";
                
    $headers "MIME-Version: 1.0\r\n";
                
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
                
    $headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
                
    $headers .= "From: Registration<register@website.com>\r\n";
                
    $mailsent mail($to$subject$message$headers); 
    I get the from as something@box27.host.com But in the first line of the email message it says "From: Registration" But nowhere does it say register@domain.com. I also get errors is i try to do the -f register@domain.com thing.

  • #7
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Solution

    PHP Code:
    ini_set(sendmail_from$from);  //where $from is the person sending the mail
    mail($to$subject$msg$header);
    ini_restoresendmail_from ); 

    I take no responsibility for the above nonsense.


    Left Justified

  • #8
    New Coder
    Join Date
    Sep 2005
    Location
    Romania
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by 700lbGorilla
    Yeah, having the same problem

    I get the from as something@box27.host.com But in the first line of the email message it says "From: Registration" But nowhere does it say register@domain.com. I also get errors is i try to do the -f register@domain.com thing.

    try to move From: before MIME... like this
    PHP Code:
    $to $e;
                
    $subject "One more step";
                
    $message "Hello, <br><br>";
                
    $message .= "Just one more step and you will be on your way to joining <a href=\"http://www.webiste.com\" target=\"_blank\">Website</a><br><br>";
                
    $headers "From: Registration<register@website.com>\r\n";
                
    $headers .= "MIME-Version: 1.0\r\n";
                
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
                
    $headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

                
    $mailsent mail($to$subject$message$headers); 
    Last edited by petronel; 09-25-2005 at 03:07 PM.

  • #9
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mindlessLemming
    PHP Code:
    ini_set(sendmail_from$from);  //where $from is the person sending the mail
    mail($to$subject$msg$header);
    ini_restoresendmail_from ); 
    Can you further explain that, not sure how that fits into my code. I'm still having no luck with the other solutions.

  • #10
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by 700lbGorilla
    Can you further explain that, not sure how that fits into my code. I'm still having no luck with the other solutions.
    Code:
     $to = $e;
                $subject = "One more step";
                $message = "Hello, <br><br>";
                $message .= "Just one more step and you will be on your way to joining <a href=\"http://www.webiste.com\" target=\"_blank\">Website</a><br><br>";
                $headers = "MIME-Version: 1.0\r\n";
                $headers .= "Content-type: text/html; charset=iso-8859-1\n";
                $headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
                $headers .= "From: 'Registration' <register@website.com>\n";
                $headers .= "Return-Path:register@website.com\n";
                $headers .= "X-Sender: register@website.com\n";
                ini_set(sendmail_from, 'register@website.com'); 
                $mailsent = mail($to, $subject, $message, $headers); 
                ini_restore( sendmail_from ); 
    if($mailsent) echo 'w007!';
    That should give the desired result for all email clients, including Gmail and Hotmail. [No more '(unknown sender)' garbage for Gmail users!]


    You should be testing this on a live server. Trying to use mail() from a localhost server on a Windows box is hell.

    Here's a complete contact form w/ php source that may be helpful: http://leftjustified.net/lab/simple-safe-php-email/
    ^ also includes checks for attempted email injection attacks

    Feel free to use as you wish
    Last edited by mindlessLemming; 09-26-2005 at 05:24 AM.

    I take no responsibility for the above nonsense.


    Left Justified

  • #11
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, that still didn't work, using that inserts "From: 'Registration' Return-Path:register@domain.com X-Sender:register@domain.com" into the beginning of the actual message. Thinking I need to contact my webhost and see if they are blocking the ability to alter who it is from.

  • #12
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    I've never used \n\r in email headers -- that may have been your problem.
    When I actually tested your script I got the same result as you

    A quick hack and ftp later, I can assure you this one works under PHP 4.3.10 and the mail is perfect when received by a Gmail account

    PHP Code:
    <?php
    $to 
    $e;
                
    $subject "One more step";
                
    $message "Hello, <br><br>";
                
    $message .= "Just one more step and you will be on your way to joining <a href=\"http://www.webiste.com\" target=\"_blank\">Website</a><br><br>";
                
    $headers "From: 'Registration' <register@website.com>\n";
                
    $headers .= "Return-Path:register@website.com\n";
                
    $headers .= "X-Sender: register@website.com\n";
                
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
                
    $headers .= "MIME-Version: 1.0\n";
                
    $headers .= "Content-Transfer-Encoding: 7bit\n";
                
    ini_set(sendmail_from'register@website.com'); 
                
    $mailsent mail($to$subject$message$headers); 
                
    ini_restoresendmail_from ); 
    if(
    $mailsent) echo 'w007!';
    ?>

    I take no responsibility for the above nonsense.


    Left Justified

  • #13
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I uses PHP 4.3.11 and it still didn't work, is it possible for a host to stop this? I'm going to contact them and see why this keeps happening.

  • #14
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yep, sounds like it's your host.
    Just wanted to make sure you were using a correct script so the host had no option of saying "OMFG!!! RTFM j00 n00b!" or the customer service equivalent.

    I take no responsibility for the above nonsense.


    Left Justified

  • #15
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I figured it out before I contacted them, I was just testing to see if the script would work. But I guess in order to have a from address, that account has to actually exist. Not sure if this is a normal thing, I just thought whatever the from was, it would work. As soon as I changed it to a from: address that actually existed, it worked like a charm. So is this a host precaution to controlling spamming? Or is this a mail() rule that I wasn't aware of?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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