PDA

View Full Version : PHP form


Jim_Shady
03-23-2006, 04:47 PM
Heya... would someone please glance at this for me? Done very little PHP and it won't work... woe is me. I took it from the tutorial very kindly offered. The form is here:

http://www.mgf-labs.com/ContactUs.htm

Thanks a million....Shady

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Enquiry from website';

// Your email address. This is where the form information will be sent.
$emailadd = 'mye-mail@gmail.com';

// Where to redirect after form is processed.
$url = 'http://www.mgf-labs.com/confirmation.htm';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
</body>
</html>

Creative Insanity
03-23-2006, 06:35 PM
Tell you what.. use Rams php file from his tut.. I use that one and it is awesome.
Just make your form, add names to each of your fields and then make the action to Ram's php file for the name you called it.
I called it contact.php.
This is an awesome little script and I have it working with repeat regions.

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'enter your subject line';

// Your email address. This is where the form information will be sent.
$emailadd = 'email to send form to';

// Where to redirect after form is processed.
$url = 'thankyou.php';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

Jim_Shady
03-23-2006, 09:52 PM
I have done but it's not working. I press submit - and it goes to the PHP - and then takes me to my thankyou page - but the info doesn't arrive at my e-mail address. See m code above - it's basically identical to the tutorial that was put up - I thought I'd followed it but am obviously missing something.

kona72
03-23-2006, 10:26 PM
Maybe a silly question but are you sure your server has PHP??

Creative Insanity
03-23-2006, 11:23 PM
If you are testing this locally then IT WON'T WORK, for the simple reason that you have not got an email server setup. Use it in your web hosting space as it needs an email server to send out the email.

Jim_Shady
03-24-2006, 09:09 AM
No... it's not a silly question! I'm testing it on the server - which I thought has php... but it might be a good idea for me to double check! Will do now...

Thanks.

Jim_Shady
03-24-2006, 10:17 AM
Just got reply from the hosting people ...

Yes, your site is hosting on our Windows Shared Servers, and PHP v4.3.1 is running on there - available for your use.

... seems it does support PHP. Does the PHP code above that I am using look ok? With this form? www.mgf-labs.com/contactus.htm

Sorry for being a pain and thank you for any help.

Shady

desertdirk
03-25-2006, 03:04 AM
you sure you are using the right email addy in the form? it is different than what you have on your web page.
DD

Jim_Shady
03-27-2006, 09:14 AM
Yeah.... I didn't want the test e-mails going to the client... so I put mine in... then I can also check that it's working!

davidj
03-27-2006, 09:47 AM
drop a file called info.php on your host space
just add this to it...

<?php phpinfo(); ?>
now browse the file through the browser using..
http://www.domain.com/info.php

this will confirm that PHP is setup correctly

Jim_Shady
03-27-2006, 03:59 PM
Cheers guys. I'm going to have a play with it when I get home from work - haven't got any FTP access at work to mess around with it - will report back tomorrow!

Shady