I currently use the free form mail script from the B & T's script and tip site, and it works very well, its located here: http://tips-scripts.com/?tip=form_mail#tip
Here is the B&T code:
- - Start Script Here - -
<?php
if ($_POST['action'] == "go") {
session_start();
$name = $_POST['name'];
$email = $_POST['email'];
$content = $_POST['content'];
if (!preg_match("(^[-\w\.]+@([-a-z0-9]+\.)+[a-z]{2,4}$)i", $email)) $alert = "You have entered an invalid email address.";
if ($name == "" OR $email == "" OR $content == "") $alert = "To send a message, please complete all 3 fields.";
if ($_SESSION['mail_count'] >= "3") $alert = "Only 3 messages can be sent per session.";
if (!$alert) {
if (!isset($_SESSION['mail_count'])) $_SESSION['mail_count'] = 0;
$_SESSION['mail_count']++;
$message .= "Name as follows:\n\n";
$message .= "$name\n\n";
$message .= "Email address as follows:\n\n";
$message .= "$email\n\n";
$message .= "Message as follows:\n\n";
$message .= "$content\n\n";
mail("mail@yourdomain.com", "yourdomain.com Message" , "$message", "From: Website <>");
$name = "";
$email = "";
$content = "";
$alert = "Your message has been sent.";
}
}
?>
<html>
<head>
</head>
<body>
<table align=center cellspacing="0" cellpadding="5" border="1" style="height: 450px; width: 500px; margin-top: 50; border-style:inset;">
<tr><td align="center"><form method=post action="mail.php"><br>
Send me a message<br><br>
your name<br><input type=text style="width: 330px;" name=name value="<?=$name?>" maxlength=50><br><br>
your email address<br><input type=text style="width: 330px;" name=email value="<?=$email?>" maxlength=50><br><br>
your message<br><textarea name="content" rows="6" cols="40"><?=$content?></textarea>
<br><br>
<input type="submit" name="submit" value="submit">
<input type="hidden" name="action" value="go">
</form></td></tr>
</table>
<?php
if ($alert) {
echo "<script type='text/javascript'>
<!--
alert ('$alert');
//-->
</script>";
}
?>
</body></html>
- - End Script Here - -
But also needed to ad a captcha type of picture to help keep down the fake mailings. Anyone know How I can incorpate this free captcha code into the exsisting B&T script code so that I can have one button to push and submit?
Both codes work very well on there own but I dont know how to call them both with one button.
here is the captcha code.
<?php
require_once( 'class.captcha.php' );
if (empty($_GET['session_code']))
{ $session_code = md5(round(rand(0,40000))); }
else
{ $session_code=$_GET['session_code']; }
$my_captcha = new captcha( $session_code, '__TEMP__/' );
$do = $_GET['do'];
if ($do == 'verify')
{
if ($my_captcha->verify( $_POST['password'] ) )
{
echo "You entered the correct password!";
exit;
}
}
$pic_url = $my_captcha->get_pic( 4 );
echo <<<FORM
<form name="form1" method="post" action="$PHP_SELF?do=verify&session_code=$session_code">
<p><img src="captcha_image.php?img=$pic_url"></p>
<p>Displayed Code? <input type="text" name="password"></p>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
FORM;
?>