03-11-2010, 07:32 PM
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 (http://w3schools.com/php/php_mail.asp) 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?
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.
03-11-2010, 08:30 PM
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):
$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.
03-12-2010, 02:05 PM
This may help, either as a drop in solution or an example for what you need to do.
03-12-2010, 09:43 PM
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.
03-13-2010, 01:51 PM
download software from forms2go demo version available by that u can create good script......