How to send email with from data in headers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lisa007
    New Member
    • Apr 2010
    • 29

    How to send email with from data in headers

    The following email code is sending the values but is not sending all the values from the form.
    Code:
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    $name = $_POST["name"];
    $from = $_POST["from"];
    mail('xxxx@hotmail.co.uk', 'My Subject', $message, $from);
    I tried to just insert the values ($name $subject) on that line but on the email it will only post two values.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Look at how the function is used in the manual entry. Study that page; everything is explained there. There are even a number of examples that show exactly how to use the function for various purposes.

    If that doesn't get you any closer, you may need to study how email actually works; what exactly makes up an email. That may help you understand the terms used in the manual, and how to properly use the input parameters.

    I could explain all this here, but it seems rather redundant. All this information is widely available online, only a Google search away.

    Comment

    • lisa007
      New Member
      • Apr 2010
      • 29

      #3
      I looked at it and it seems that my thick head can't get way around it. With email you need the form, to, subject, and body. I don't understand the extra parameters for the header.
      Last edited by Niheel; May 21 '10, 01:19 AM. Reason: lisa007, Please use proper grammar, punctuation and spelling. If we can't understand your posts, we can't answer them.

      Comment

      • Niheel
        Recognized Expert Moderator Top Contributor
        • Jul 2005
        • 2432

        #4
        The call to the mail function in your code is wrong:

        Use:
        Code:
        $to = "xxxx@hotmail.co.uk";
        $subject = $_POST["subject"];
        $message = $_POST["message"];
        $name = $_POST["name"];
        $from = $_POST["from"];
        mail($to,$subject,$message);
        If you want to send FROM you'll have to manipulate the headers and you can use code like this:
        Code:
        <?php
        $to = "xxxx@hotmail.co.uk";
        $subject = $_POST["subject"];
        $message = $_POST["message"];
        $name = $_POST["name"];
        $from = $_POST["from"];
        $headers = "From: $name <$from>" . "\r\n";
        
        mail($to,$subject,$message,$headers);
        ?>
        As Atli suggested use http://php.net/manual/en/function.mail.php as a guide to help you create the mail output you want.
        niheel @ bytes

        Comment

        • lisa007
          New Member
          • Apr 2010
          • 29

          #5
          Thank you very much. It works beautifully now I will try my best to understand better the email concept form the php manual.
          Last edited by Niheel; May 21 '10, 01:23 AM. Reason: Spelling, grammar and punctuation. Once again, post questions properly so people can read them.

          Comment

          Working...