SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,930
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    From appearing mysetriously in e-mail

    I have a form that e-mail's me a user's comments.

    The strange thing is, is that the "FROM" address is appearing in the e-mail even though I never include it in my mail() statement.

    How is that possible?!

    PHP Code:
        // Check for Data-Entry Errors.
        
    if (empty($errors)){
            
    // Form data clean.

            // E-mail Inquiry to Administrator.
            
    $to 'debbie@mail.com';
            
    $subject $trimmed['subject'];
            
    $inquiry $trimmed['inquiry'];
    //        $from = $trimmed['senderEmail'];
            
    mail($to$subject$inquiry);
        } 

    When I get the e-mail in my inbox I see...
    Code:
    Subject:	Test
    From:		user1@user1s-macbook.local
    Date:		Mon, Oct 10, 2011 9:31 pm
    To:		debbie@mail.com
    Sincerely,


    Debbie

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you don't specify a "From" header PHP will insert the default server address so that the email has a valid sender. Otherwise your emails will look like spam.

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,930
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by programthis View Post
    If you don't specify a "From" header PHP will insert the default server address so that the email has a valid sender. Otherwise your emails will look like spam.
    So what is the proper syntax to get who is sending me the comments from the form? (i.e. the sender's e-mail)


    Debbie

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the additional_headers parameter of the mail function. Use the $from variable and add it as the 4th parameter.
    PHP Code:
    // E-mail Inquiry to Administrator.
            
    $to 'debbie@mail.com';
            
    $subject $trimmed['subject'];
            
    $inquiry $trimmed['inquiry'];
            
    $from 'From: '$trimmed['senderEmail'] ."\r\n";
            
    mail($to$subject$inquiry$from); 

  5. #5
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,930
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by programthis View Post
    Use the additional_headers parameter of the mail function. Use the $from variable and add it as the 4th parameter.
    PHP Code:
    // E-mail Inquiry to Administrator.
            
    $to 'debbie@mail.com';
            
    $subject $trimmed['subject'];
            
    $inquiry $trimmed['inquiry'];
            
    $from 'From: '$trimmed['senderEmail'] ."\r\n";
            
    mail($to$subject$inquiry$from); 

    1.) Why do you have \r\n at the end of the $from variable?

    2.) Can you name the parameters anything in mail()??

    I thought you have to use mail($to, $subject, $body, $headers)?


    Debbie

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,863
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    1.) Why do you have \r\n at the end of the $from variable?
    Bacause that is the separator that you have to use between headers.

    Quote Originally Posted by DoubleDee View Post
    2.) Can you name the parameters anything in mail()??

    I thought you have to use mail($to, $subject, $body, $headers)?
    The values you are passing in are To, Subject, Body, and Headers. What variables you set up to contain those values is up to you.

    In this case since the only header you are supplying is the From header it is just as easy to call it $from as to call it $headers as from is more descriptive of what it currently contains.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,930
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Bacause that is the separator that you have to use between headers.



    The values you are passing in are To, Subject, Body, and Headers. What variables you set up to contain those values is up to you.

    In this case since the only header you are supplying is the From header it is just as easy to call it $from as to call it $headers as from is more descriptive of what it currently contains.
    Okay, thanks.


    Debbie


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
  •