FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Form Mailer





aningbo
Many users have been having problem regarding forms and I hope this will be made sticky and to be shown to everyone without having the newbies to look for it again and again...

here's the form and name it as contactme.php

Code:
<?php
$im = ImageCreate(200, 40);  //create image
$white = ImageColorAllocate($im, 0,0, 0);
$black = ImageColorAllocate($im, 120, 200, 68);
srand((double)microtime()*1000000);
$string = rand(1,10); //the first number
$string2=rand(1,10); //the second number
$string3="$string + $string2";
$verification = $string3;
$thevalue=$string+$string2;
ImageFill($im, 0, 0, $black);
ImageString($im, 4, 70, 10, $verification, $white);
Imagejpeg($im, "images/verify.jpeg");
ImageDestroy($im);

print "<form action='formemail.php' method='post'><input type='hidden' name='thankspage' value='thanx.php'><input type='hidden' name='ccsubmitter' value='yes'>";
print "<table><tr><td><font face='Arial' size='2'><b>Name</b></font></td><td>";
print "<input type='text' size='35' maxlength='256' name='name' style='border: 1px solid #000000'></td></tr>";
print "<tr><td><font face='Arial' size='2'><b>E-Mail</b></font></td><td><input type='text' size='35' maxlength='256' name='email' style='border: 1px solid #000000'></td></tr>";
print "<tr><td><font face='Arial' size='2'><b>Location</b></font></td><td><input type='text' size='35' maxlength='256' name='location' style='border: 1px solid #000000'></td></tr>";
print "<tr><td><font face='Arial' size='2'><b>Website</b></font></td><td><input type='text' size='35' maxlength='256' name='website' style='border: 1px solid #000000'></td></tr>";
print "<tr><td><font face='Arial' size='2'><b>Reason</b></font></td><td><input type='text' size='35' maxlength='256' name='website' style='border: 1px solid #000000'></td></tr>";
print "<tr><td valign='absmiddle'><font face='Arial' size='2'><b>Add me</b></font></td valign='absmiddle'><td><input type='hidden' value='$thevalue' name='hiddenvalue'><img src='images/verify.jpeg' border='0' align='absmiddle'> <input type='text' name='yourcode' size='5'><td></tr>";
print "<tr><td><font face='Arial' size='2'><b>Comment</b></font></td><td><textarea rows='10' name='comment' cols='37' style='border: 1px solid #000000'></textarea></td></tr>";

print "<tr><td></td><td><input type='submit' name='submit' value='::.. Send ..::' style='color: #000000; background-color: #F5F5FF' ></td></tr>";
print "</table></form>";
?>


and here's the php file that will process your form. name it as formemail.php:

Code:
<?php
if(isset($_POST['submit']))
{
$yourcode=$_POST['yourcode'];
$hiddenvalue=$_POST['hiddenvalue'];
if($yourcode==$hiddenvalue)
{
print "Thank you for contact me. <a href='../index.php'>HomePage</a>";
// enter the mailer here
//like
$adminemail = 'you email address';

$version = '1.10';
$controlvars = ' thankspage submitteremail ccsubmitter ';
$messagetoadmin = $HTTP_POST_VARS['submitteremail'] ." has filled out a form with this content:


";
$messagetosubmitter = "You have submitted a form with the content listed below. thank you.


";
while(list($key, $value) = each($HTTP_POST_VARS))
{
if (!stristr($controlvars, ' '. $key .' '))
{
$messagetoadmin .= $key .': '. $value .'

';
$messagetosubmitter .= $key .': '. $value .'

';
}
}
mail($adminemail, 'Form Submitted: '. stripslashes($HTTP_POST_VARS['subject']), stripslashes($messagetoadmin), 'From: '. $HTTP_POST_VARS['submitteremail']);

if ($HTTP_POST_VARS['ccsubmitter'] == 'yes')
{
mail($HTTP_POST_VARS['submitteremail'], 'Form Submitted: '. stripslashes($HTTP_POST_VARS['subject']), stripslashes($messagetosubmitter), 'From: '. $adminemail);
}
if ($_POST['autoresponse'] != '')
{
$body = geturl($autoresponse);
mail($submitteremail, 'Re: '. stripslashes($HTTP_POST_VARS['subject']), stripslashes($body), 'From: '. $adminemail);
}
//just copied some code from post above, not sure if you need more code or less just example to give you and idea
}
else
{
print "You verification code is not right. Please go back and try again.";
}

}
?>



open contactme.php and you are ready to go. there's also a anti-SPAM enabled. these are not really my codes but not sure as to where i gathered all this codes from! share it.
aningbo
u may also add as many fields as you want... unlimited number of fields can be added.

enjoy Twisted Evil
sonam
Hm, you are mixed super globals and old way wiht vars.

From php.net
Quote:
$_POST
Variables provided to the script via HTTP POST. Analogous to the old $HTTP_POST_VARS array (which is still available, but deprecated).


I have one big reason why you must change this. Here is (from php.net):

Quote:
PHP 4 end of life announcement
[13-Jul-2007]
Today it is exactly three years ago since PHP 5 has been released. In those three years it has seen many improvements over PHP 4. PHP 5 is fast, stable & production-ready and as PHP 6 is on the way, PHP 4 will be discontinued.

The PHP development team hereby announces that support for PHP 4 will continue until the end of this year only. After 2007-12-31 there will be no more releases of PHP 4.4. We will continue to make critical security fixes available on a case-by-case basis until 2008-08-08. Please use the rest of this year to make your application suitable to run on PHP 5.


Sonam
aningbo
oh well thats interesting...

will be working on it when i get the time... untill then. so busy with my classes...
Related topics
PHP: Feedback form issues.. help =P
Web Mailer, Create a "contact us" mailer
My Mailer Script
form mail for php
A Simple Form Mail in PHP
form button to open a custom sized new window
Server Changes Since Crash?
Fantastic form creator program
Need help with submitting form
Universal Form-Processing tool
AJAX and PHP contact form
verzend formulier
formulieren maken testen mislukt
Problem with form
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.