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.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    113
    Thanks
    27
    Thanked 0 Times in 0 Posts

    help creating a contact form

    I've just started learning PHP and need to create a contact form for a website. I've read through the PHP Mail documentation at w3schools.com and think I understand it pretty well. However, I'm wondering how I can add more fields to the form to incorporate more information into the body of the e-mail. If the mail function has to follow the pattern below, how do I put more than one item in the "message" area?

    Code:
    mail(to,subject,message,headers,parameters)
    I'll need to be able to set up additional text fields and a couple dropdown menus and have the info from those fields write to the e-mail. Can someone help me set this up? Thanks.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Assuming you're understanding how to pass data between the form and the script, its a matter of simply adding additional data to $message (or whatever you named it):
    PHP Code:
    $to 'fouLu@mysite.com';
    $subject 'This is a test email.';
    $message 'This email is a test, you filled in the following data:' PHP_EOL;
    $message .= 'Name: ' $_POST['name'] . PHP_EOL;
    $message .= 'Email: ' $_POST['email'] . PHP_EOL;

    mail($to$subject$message); 
    Pretty insecure example, but it demonstrates its purpose. PHP you can string concatenate with .= to you're variable. Also, strings can span multiple lines, or break with $msg = "Data " . $data . " is here". Double quoted strings are parsed as PHP code as well, so primitive variables will be expanded into their representation (as long as you're not adding like 's or anything to it, that needs to take a complex form). There is also a syntax known as heredoc which can take strings over multiple lines. Heredoc is a great option if you want to avoid quotation escaping, but fails when put in a function (as in, it sucks in there, not that it won't work). The reason why is because the ending delimiter MUST be on a newline by itself and MUST NOT have any preceding white space. So you're formatting goes all ary. Being that PHP is a string based language though, you'll find that there are tons of ways to manipulate strings quite easily.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    mightypants (03-12-2010)

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    This may help, either as a drop in solution or an example for what you need to do.

    http://green-beast.com/gbcf-v3/

  • Users who have thanked MattF for this post:

    mightypants (03-12-2010)

  • #4
    Regular Coder
    Join Date
    Jun 2008
    Posts
    113
    Thanks
    27
    Thanked 0 Times in 0 Posts
    Thanks for your responses, I think I've got a handle on it for now. I'm sure I'll run into more issues as I mess around with it.

  • #5
    New Coder
    Join Date
    Feb 2010
    Location
    ahmedabad
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    download software from forms2go demo version available by that u can create good script......
    Last edited by scripts99; 03-13-2010 at 12:55 PM.
    ---------------------------------------------------
    Search Engine Script - Justdial Clone
    Download PHP Script - Complete Portal Website


  •  

    Posting Permissions

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