+ Post New Thread
Results 1 to 6 of 6
Web Development Thread, Including multiple fields in form mailer in Coding and Web Development; I got this PHP code off a site and its works great. But I added a new field called 'name' ...
  1. #1

    Join Date
    Mar 2009
    Location
    Chicago
    Posts
    25
    Thank Post
    9
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Including multiple fields in form mailer

    I got this PHP code off a site and its works great. But I added a new field called 'name' and I cant find out a way to include that field when the results are emailed to me. Right now, the only thing I get in the message field of my email is the $message. I tried adding, $message,$name but then I get an error and the email does note even get sent.

    What I want is for the email I get to include the $message and the $name fields. Right now it just includes the $message field
    Code:
    <?php
      $email = $_REQUEST['email'] ;
      $message = $_REQUEST['message'] ;
      $name = $_REQUEST['name'];
    
      mail( "blah@blah.com", "Form Results",
        $message, "From: $email" );
      header( "Location: thankyou.html" );
    ?>

  2. #2


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,678
    Thank Post
    352
    Thanked 794 Times in 714 Posts
    Rep Power
    346
    Hi Jim,

    This should suffice.

    Kim.

    Code:
    <?php
      $email = $_REQUEST['email'] ;
      $message = $_REQUEST['message'] ;
      $name = $_REQUEST['name'];
    
      mail( "blah@blah.com", "Form Results",
        "Name: $name\nMessage: $message", "From: $email" );
      header( "Location: thankyou.html" );
    ?>

  3. Thanks to kmount from:

    -Jim (27th March 2009)

  4. #3

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Code:
    <?php
      $email = $_REQUEST['email'] ;
      $message = $_REQUEST['message'] ;
      $name = $_REQUEST['name'];
    
      mail( "blah@blah.com", "Form Results",
        $message, "From: $name <$email>" );
      header( "Location: thankyou.html" );
    ?>

    Other vague improvement:

    Code:
      if( mail( "blah@blah.com", "Form Results",   $message, "From: $name <$email>" ))
      {
        header( "Location: thankyou.html" );
      } else {
        header("Location: sorrycouldntbedone.html");
      }

  5. Thanks to powdarrmonkey from:

    -Jim (27th March 2009)

  6. #4

    Join Date
    Mar 2009
    Location
    Chicago
    Posts
    25
    Thank Post
    9
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    It worked and I can easily follow it if I want to add more fields. thx

  7. #5


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,678
    Thank Post
    352
    Thanked 794 Times in 714 Posts
    Rep Power
    346
    Aye, I'm not a php ledg.

  8. #6

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Sorry, it was a race condition

SHARE:
+ Post New Thread

Similar Threads

  1. Formatting Data Fields
    By tw15ns in forum MIS Systems
    Replies: 1
    Last Post: 3rd January 2009, 03:38 PM
  2. [MS Office - 2003] Access - Calculated Fields
    By garethedmondson in forum Office Software
    Replies: 2
    Last Post: 11th December 2008, 03:22 PM
  3. SWGFL php mailer total CRUD
    By sgknowler in forum Web Development
    Replies: 0
    Last Post: 10th September 2008, 11:04 AM
  4. Quick letter fields not substituted
    By cjohnsonuk in forum MIS Systems
    Replies: 4
    Last Post: 20th March 2008, 01:42 PM
  5. pc booking systems including my-pc
    By in forum Network and Classroom Management
    Replies: 8
    Last Post: 9th March 2007, 07:28 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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