Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-11-2010, 06:32 PM   PM User | #1
mightypants
Regular Coder

 
Join Date: Jun 2008
Posts: 113
Thanks: 27
Thanked 0 Times in 0 Posts
mightypants is an unknown quantity at this point
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.
mightypants is offline   Reply With Quote
Old 03-11-2010, 07:30 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
mightypants (03-12-2010)
Old 03-12-2010, 01:05 PM   PM User | #3
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
This may help, either as a drop in solution or an example for what you need to do.

http://green-beast.com/gbcf-v3/
MattF is offline   Reply With Quote
Users who have thanked MattF for this post:
mightypants (03-12-2010)
Old 03-12-2010, 08:43 PM   PM User | #4
mightypants
Regular Coder

 
Join Date: Jun 2008
Posts: 113
Thanks: 27
Thanked 0 Times in 0 Posts
mightypants is an unknown quantity at this point
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.
mightypants is offline   Reply With Quote
Old 03-13-2010, 12:51 PM   PM User | #5
scripts99
New Coder

 
Join Date: Feb 2010
Location: ahmedabad
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
scripts99 is an unknown quantity at this point
download software from forms2go demo version available by that u can create good script......
__________________
---------------------------------------------------
Search Engine Script - Justdial Clone
Download PHP Script - Complete Portal Website

Last edited by scripts99; 03-13-2010 at 12:55 PM..
scripts99 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:02 PM.


Advertisement
Log in to turn off these ads.