PDA

View Full Version : Php Mail script like Hostedscripts


smwebs
06-08-2003, 05:30 PM
hi, i am trying to learn about how does HostedScripts.Com form-2-Mail script Parses all the Variable of his user Form??

i mean let take it like this
i am a user my username is Smwebs
i make a form on my page, and give the Form Action to their script
and when the user submits that form it goes to the script the script checks the page for all the form fields and makes a output based on the user inputs and then when press submit again it mails it to the approperiate person.. how does it happen? i mean when we make one thing we have to define the fields we want to send via form like this

mail($myemail, $mysubject, $myfield1, $myfield2, $myfield3";)

right? then what will be the variable which allow to do something like hostedscripts do :D

is there any or it is only in .cgi's scriptS?

Thanks in Advance
Salman
Smwebs.2ya.Com

missing-score
06-08-2003, 07:21 PM
I havent seen the script, but it could use a foreach loop.

eg:

Say I have a form (posted, method="post") with the following fields:

Name
Surname
E-mail Address
Website

And I want to add all of them to the e-mail...



<?php

$cont = "";

foreach($_POST as $key=>$val){
$cont .= $key." : ".$val."\n";
}

?>


Would create a string of all the posted variables and their values...

As for functions with unknown ammounts of agruments (looks like it above anyways) look up:

func_num_args() and func_get_arg() in the php manual...

http://www.php.net/func-num-args
http://www.php.net/func-get-arg

smwebs
06-09-2003, 12:36 PM
ermm my mistake i am a newbie i dont know all this :<
where this code should go? in the mailit.php file? or in the myform.html file :S Sorry, please explain :D

whackaxe
06-09-2003, 12:54 PM
in the long run you would be better off learning php and making your own form2mail script

smwebs
06-09-2003, 01:08 PM
what does this mean?? you mean to say that after some time i wll quit laerning php and will start using the remotely hosted scriptS?
:( sowwie am very bad in english u see :D

whackaxe
06-09-2003, 01:20 PM
:D

what i mean is that instead of having hostedscripts (which give you ads and loads of other horrible things) you should learn PHP. php will enable you to make your own form2mail script

smwebs
06-09-2003, 01:55 PM
thats what i am saying i know how to make a form2mail script but what my intentions here are to get a one mailit.php file which can process all forms on myForms.html on my different sites, they all have different fields so there are lots of different variable i dont want to make different mailit.php for different forms dats why i asked that is there a way like in hostedscripts that php can Check the page for all the fields/inputs filled and then after changing them in varialbes it can list them on the main page with the Input Name : Input Value Manner and at the same time send that info in the same manner to the respective recipcient

is it possible pleaje :D

smwebs
06-10-2003, 06:19 PM
hello any one..., i think its a simple question but the answer may be not simple :P but any one hellow please..

missing-score
06-10-2003, 07:51 PM
Rite, you shouldnt bump topics...

So, what do you want to do? Do you want a script that will e-mail you all the info from a form? shouldnt be too hard...



$strmsg = "Someone hass filled in and sent your form...\n\n";

$strmsg .= "There were ".count($_GET)." GET vars sent in the form...\n------------\n";

foreach($_GET as $key=>$val){
$strmsg .= $key.": ".$val;
}

$strmsg .= "\n------------\n\n";

$strmsg .= "There were ".count($_POST)." POST vars sent in the form...\n------------\n";

foreach($_POST as $key=>$val){
$strmsg .= $key.": ".$val;
}

$strmsg .= "\n------------\n\n";

$strmsg .= "End of form\n";

$header = "From: email@address.com\r\n";

if(mail("email@address.net", "New Registration", $strmsg, $header)){
echo "Mail sent";
} else {
echo "Mail not sent, plz retry...";

smwebs
06-11-2003, 12:56 AM
Parse error: parse error, unexpected $ in /home/salman/public_html/form2mail.php on line 32

this is what i get :(

Below is the Source of form2mail.php file

<?php


$strmsg = "Someone hass filled in and sent your form...\n\n";

$strmsg .= "There were ".count($_GET)." GET vars sent in the form...\n------------\n";

foreach($_GET as $key=>$val){
$strmsg .= $key.": ".$val;
}

$strmsg .= "\n------------\n\n";

$strmsg .= "There were ".count($_POST)." POST vars sent in the form...\n------------\n";

foreach($_POST as $key=>$val){
$strmsg .= $key.": ".$val;
}

$strmsg .= "\n------------\n\n";

$strmsg .= "End of form\n";

$header = "From: iamsalmanpk@yahoo.com\r\n";

if(mail("iamsalmanpk@yahoo.com", "New Registration", $strmsg, $header)){
echo "Mail sent";
} else {
echo "Mail not sent, plz retry...";


?>
:(

missing-score
06-11-2003, 04:20 PM
ahhh...

Just add a } on the end, like:

else {
echo "Plz retry";
}

brothercake
06-11-2003, 05:12 PM
You just need to establish a convention for form data - so email addresses are always $_POST["email"] and real names are always $_POST["realname"] and so forth. Then you can use one generic mail script for all your forms.

Taking it a bit further, you can have hidden fields in the form that validate entry, such as required fields:

<input type="hidden" name="required" value="email,realname" />

then you split up $_POST["required"] and check off each value in turn to make sure it's there.

smwebs
06-13-2003, 06:48 AM
Worked :) Thanks missing-score

brothercake if i was that intelligent then i would have guessed the } thingie too ;) but any wayz i would like to know this thing too, cause i hostedscripts or some other scripts hosting site has this feature too & by the way the script i made from this help is now used in our school by more then 100+ users per day, not in forms but in websites i mean my fellow students asked me for source i gave them the source they also tried to learn and almost everyone of them is now using the script on their own site :) Thanks once again.

missing-score
06-13-2003, 07:43 AM
brothercake, I can see one problem with what you are doing...

If you have a hidden form field, if you get someone view the source of the html page, find out the form name, they could just type something like:

javascript:documnet.form.required.value = '';

in the address bar, which works, taking off any required fields.