Click to See Complete Forum and Search --> : php form


nubs75
12-09-2005, 01:55 PM
I have created a form using php that consists of two files; the first file is called "contact.html" and the second file is called "contact.php". The submitter is supposed to enter his/her name and email address and hit the "send" button. The form should then be email to my email address and a courtesy reply should also be sent out to the submitter via the email address from the form. The url for my form is: http://microsale-pos.com/TestStuff/Microsale3/contact.html. Any help would be appreciated as i am new to php and am not sure what im doing. Below is the code for the two files:

"CONTACT.HTML"

<html>

<head>
<title>Demo Download Interest</title>
<style>
BODY{color:#000000; font-size: 8pt; font-family: Verdana}
.button {background-color: rgb(128,128,128); color:#ffffff; font-size: 8pt;}
.inputc {font-size: 8pt;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>

<body bgcolor="#666666" text="#FFFF00" link="#FFFFFF">
<form name="phpformmailer" action="contact.php" align="center" method="post">
<div align="center"><center>
<table width="617" align="center" cellspacing="6" bgcolor="#000000">
<tr>
<td width="160"><div align="center"><strong><font color="#FFFF00">Demo
Download </font></strong></div></td>
<td width="433"><a
href="http://microsale-pos.com"><small>www.microsale-pos.com<strong></strong></small></a></td>
</tr>
<tr>
<td align="right" width="160"><div align="center"><small><font color="#FFFF00">Your
name</font>:</small></div></td>
<td width="433"><font face="Arial"><input class="inputc" size="29" name="name"></font></td>
</tr>
<tr>
<td align="right" width="160"><div align="center"><font color="#FFFF00" size="1">*</font><font color="#FFFF00"><small>
Your email</small></font><small>l <font color="#FFFF00">address:</font></small></div></td>
<td align="left" width="433"><font face="Arial"><input class="inputc" size="29"
name="email"></font></td>
</tr>
<tr align="middle">
<td align="right" width="160"><div align="center"><font color="#FFFF00" size="1">*</font><font color="#FFFF00"><small>
Confirm email</small></font><small>l <font color="#FFFF00">address</font>:</small></div></td>
<td width="433" align="left"><font face="Arial"><input class="inputc" size="29"
name="email2"></font></td>
</tr>
<tr>
<td align="right" width="160"><div align="center"><font color="#FFFF00" size="1">*</font><font color="#FFFF00"><small>
Subject</small></font><small>:</small></div></td>
<td width="433"><font face="Arial"><input class="inputc" size="29" name="thesubject"></font></td>
</tr>
<tr>
<td align="right" width="160"><font color="#FFFFFF">&nbsp;</font>
<p align="center"><font color="#FFFF00" size="1">*</font><font color="#FFFF00"><small>
Your request or query:</small></font></td>
<td width="433"><textarea style="FONT-SIZE: 10pt" name="themessage" rows="7" cols="27"></textarea></td>
</tr>
<tr>
<td width="160"></td>
<td width="433"><script language="JavaScript"><!--
function validateForm()
{
var okSoFar=true
with (document.phpformmailer)
{
var foundAt = email.value.indexOf("@",0)
if (foundAt < 1 && okSoFar)
{
okSoFar = false
alert ("Please enter a valid email address.")
email.focus()
}
var e1 = email.value
var e2 = email2.value
if (!(e1==e2) && okSoFar)
{
okSoFar = false
alert ("Email addresses you entered do not match. Please re-enter.")
email.focus()
}
if (thesubject.value=="" && okSoFar)
{
okSoFar=false
alert("Please enter the subject.")
thesubject.focus()
}
if (themessage.value=="" && okSoFar)
{
okSoFar=false
alert("Please enter the details for your enquiry.")
themessage.focus()
}
if (okSoFar==true) submit();
}
}
// --></script>
<font color="#FFFFFF">
<input type="button" class="button"
value="Send" name="B1" ONCLICK="javascript:validateForm()">
<small> <small><font color="#FFFF00">You must fill in the fields marked
with a *</font></small></small></font></td>
</tr>
</table>
</center></div>
</form>
</body>
</html>

"CONTACT.PHP"

<?php
/* PHP Form Mailer - phpFormMailer v2.1, last updated 30th Nov 2005 - check back often for updates!
(easy to use and more secure than many cgi form mailers) FREE from:
www.TheDemoSite.co.uk
Should work fine on most Unix/Linux platforms */

// ------- three variables you MUST change below -------------------------------------------------------
$valid_ref1="http://microsale-pos.com/TestStuff/Microsale3/contact.html";// chamge "Your--domain" to your domain
$valid_ref2="http://microsale-pos.com/TestStuff/Microsale3/contact.html";// chamge "Your--domain" to your domain
$replyemail="sales@microsale-pos.com";//change to your email address
// ------------------------------------------------------------

//clean input in case of header injection attempts!
function clean_input_4email($value, $check_all_patterns = true)
{
$patterns[0] = '/content-type:/';
$patterns[1] = '/to:/';
$patterns[2] = '/cc:/';
$patterns[3] = '/bcc:/';
if ($check_all_patterns)
{
$patterns[4] = '/\r/';
$patterns[5] = '/\n/';
$patterns[6] = '/%0a/';
$patterns[7] = '/%0d/';
}
//NOTE: can use str_ireplace as this is case insensitive but only available on PHP version 5.0.
return preg_replace($patterns, "", strtolower($value));
}

$name = clean_input_4email($_POST["name"]);
$email = clean_input_4email($_POST["email"]);
$thesubject = clean_input_4email($_POST["thesubject"]);
$themessage = clean_input_4email($_POST["themessage"], false);

$error_msg='ERROR - not sent. Try again.';

$success_sent_msg='<p align="center"><strong>&nbsp;</strong></p>
<p align="center"><strong>Your information has been successfully sent to us<br>
</strong> and we will reply as soon as possible.</p>
<p align="center">A copy of your query will be sent to you</p>
<p align="center">with a link to the demo.</p>';

$replymessage = "Hi $name

Thank you for your interest in Micro$ale POS.

Please click on the link below to begin download.

http://microsale-pos.com/demo.exe.

Below is a copy of the message you submitted:
--------------------------------------------------
Subject: $thesubject
Query:
$themessage
--------------------------------------------------

Thank you";

// email variable not set - load $valid_ref1 page
if (!isset($_POST['email']))
{
echo "<script language=\"JavaScript\"><!--\n ";
echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
exit;
}

$ref_page=$_SERVER["HTTP_REFERER"];
$valid_referrer=0;
if($ref_page==$valid_ref1) $valid_referrer=1;
elseif($ref_page==$valid_ref2) $valid_referrer=1;
if(!$valid_referrer)
{
echo "<script language=\"JavaScript\"><!--\n alert(\"$error_msg\");\n";
echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
exit;
}
$themessage = "name: $name \nQuery: $themessage";
mail("$replyemail",
"$thesubject",
"$themessage",
"From: $email\nReply-To: $email");
mail("$email",
"Receipt: $thesubject",
"$replymessage",
"From: $replyemail\nReply-To: $replyemail");
echo $success_sent_msg;
/*
PHP Form Mailer - phpFormMailer (easy to use and more secure than many cgi form mailers)
FREE from:

www.TheDemoSite.co.uk */
?>

phpmyborder
12-10-2005, 11:57 AM
i can not repeat it enough... to email, use phpmailer :)

Its a greate free tool (search 'phpmailer' in google)

NewZealand
12-10-2005, 05:25 PM
I dont understand what phpmyborder is on about but you never stated what error you are having? I went to the form, submitted my details, got redirected to a success page, so it seamed to work fine?

Also next time you post please use vb tags to encase yoour code!

[ php ]

code here

[ /php ]

nubs75
12-12-2005, 07:14 AM
You should have also received a courtesy reply email. That is where i am having the problem. It acts as though thit is working fine(giving you the success page), but it does not send the mail. Do you have any suggestions?

bokeh
12-12-2005, 07:57 AM
Go back and edit your post. Put all your code within code tags. The way you have posted it is totally unreadable. Also if you want to get an efficient response read help us to help you (http://www.webdeveloper.com/forum/showthread.php?t=64280)