Hi all,
Im creating a website for the company I work for and I have made a simple contact for that asks for Name, e-mail and then a text box where they can write there message.
Now Ive managed to style the form and it seems to work that when I hit submit it goes to a page but what it doesn't do is a) send an email to the address I have specified and b) it doesnt take the user back to the same page they were on even though I have specified this.
The section with the form is called Drop Us A Line.
Here is the code, there are 4 files:
gdform.php
PHP Code:<?php
$request_method = $_SERVER["REQUEST_METHOD"];
if($request_method == "GET")
{
$query_vars = $_GET;
}
elseif ($request_method == "POST")
{
$query_vars = $_POST;
}
reset($query_vars);
$t = date("U");
$file = $_SERVER['DOCUMENT_ROOT'] . "\ssfm\gdform_" . $t;
$fp = fopen($file,"w");
while (list ($key, $val) = each ($query_vars))
{
fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\r\n");
fputs($fp,"$val\r\n");
fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\r\n");
if ($key == "redirect")
{
$landing_page = $val;
}
}
fclose($fp);
if ($landing_page != "")
{
header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page");
}
else
{
header("Location: http://".$_SERVER["HTTP_HOST"]."/");
}
?>
gdform.php.bak
<?php
$request_method = $_SERVER["REQUEST_METHOD"];
if($request_method == "GET")
{
$query_vars = $_GET;
}
elseif ($request_method == "POST")
{
$query_vars = $_POST;
}
reset($query_vars);
$t = date("U");
$file = $_SERVER['DOCUMENT_ROOT'] . "\ssfm\gdform_" . $t;
$fp = fopen($file,"w");
while (list ($key, $val) = each ($query_vars))
{
fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\r\n");
fputs($fp,"$val\r\n");
fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\r\n");
if ($key == "redirect")
{
$landing_page = $val;
}
}
fclose($fp);
if ($landing_page != "")
{
header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page");
}
else
{
header("Location: http://".$_SERVER["HTTP_HOST"]."/");
}
?>
sendresults.php
PHP Code:<?php
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'Contact form';
// Your email address. This is where the form information will be sent.
$emailadd = 'richard.cc@stormdfx.com';
// Where to redirect after form is processed.
$url = 'http://www.stormdfx.com/stormdfx';
// 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 = '1';
// --------------------------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.'">';
?>
HTML
From the about PHP can you help me figure out what is going worng?HTML Code:<form action="gdform.php" method="post" name="ContactForm"> <fieldset> <label form="name">Name:</label> <input type="text" id="name" name="name" placeholder="Enter your full name" /> <label form="email">Email:</label> <input type="text" id="email" name="email" placeholder="Enter your email address" /> <label form="message">Message:</label> <textarea id="comments" name="comments" placeholder="What's on your mind?"></textarea> <input type="submit" name="Submit" value="Submit" /> </fieldset> </form>
Many Thanks,
Rich



Reply With Quote

Bookmarks