PDA

View Full Version : Adding additional variables in PHP/Flash email form


eposos
12-13-2006, 01:38 PM
Hi - I have been sweating over a flash/php email form for a while and thru my epic odessy have discovered that most tutorials contain the usual input data:

NAME
EMAIL
SUBJECT
MESSAGE

Lets say I wanted to add a few more input fields in the flash form, such as PHONE and REFERENCE.

How would the PHP code change in order for this input text to appear in the messasge body of the receiver's email?

Thanks - Andy

Cota
12-13-2006, 01:46 PM
that depends..what current code to you have? Its just a matter of sending more variables out to PHP and few more $_POST's in php.

eposos
12-13-2006, 02:04 PM
<?php

//create short variable names
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['message'];
$name=trim($name);
$email=trim($email);
$subject=StripSlashes($subject);
$message=StripSlashes($message);

/*#########
modify the next line with your own email address
###########*/

$toaddress='thoang@helminvestment.com';


if (preg_match ("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|a s|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn |bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|c l|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk| dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|f o|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs |gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|in t|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr| kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md |mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum |mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|n p|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr |pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg| sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf |tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|u m|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za| zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email)) {
mail($toaddress,$subject,$message,"From: $name <$email>\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
//clear the variables
$name='';
$email='';
$subject='';
$message='';
echo "response=passed";
} else {
echo "response=invalid";
exit;
}

?>

again, I want to pass a few more variables thru this form so they are displayed in the body of the email message

Cota
12-13-2006, 02:09 PM
just add

$message=StripSlashes($message);
$message.=$_POST['extraVar'];
$message.=$_POST['YetAnoterVar'];

eposos
12-13-2006, 02:37 PM
Hey Cota, thanks for the tip....it works but
all the input text gets mashed together into one line....would be nice to add line breaks in between each variable entered...thanks

Cota
12-13-2006, 05:10 PM
Something like

$message=StripSlashes($message);
$message.=$_POST['extraVar']."/r/n";
$message.=$_POST['YetAnoterVar']."/r/n";

Should work, but sometimes can be a pain.

eposos
12-13-2006, 05:41 PM
Kljhgdflughrflgsfkhds
dsklfgsldjfgsdaljf
a;sdjfhlaskdjf
;sdkjfhglkdfsjhgdfs625.587.8774/r/nGloba and such/r/n

I just typed a bucnch of junk....you can see that the info is still all mashed...
thanks for looking

CyanBlue
12-13-2006, 06:35 PM
What if you use '\r\n' instead of '/r/n'???

eposos
12-14-2006, 12:36 AM
Thanks that worked - I appreciate your time Cota and Cyan....

Cota
12-14-2006, 01:52 AM
glad we could help.