emailing html form with php
Posted: Thu Jun 30, 2011 12:57 pm
Hi,
I admit I am a novice with php right now. My problem is with this php code that I copied from a tuitorial, and I keep getting back "You have not entered an email, please go back and try again."
I'm hoping someone would help me and I would also like to send them a successful page a thank you page too.
Regards,
Lee Frandsen posting.php?mode=post&f=1#
<style type="text/css">
#recaptcha_error_box {
width:30%;
border:medium groove #A00;
background-color:#FF9;
padding:1em;
color:#900;
font-weight:bold;
font-size:80%;}
</style>
<?php
require_once('recaptchalib.php');
$privatekey = "xxxxx";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
echo '<div id="recaptcha_error_box">The reCAPTCHA failed with this message: '.$response->error.'<br />Please try again.</div>';
} else
{
$to = $_POST['leefrand@cox.net'];
$name = $_POST['name'];
$from = $_POST['email'];
$headers = "from: $from";
$subject = "estimateform";
$fields = array();
$fields{"name"} = "name";
$fields{"phone"} = "phone";
$fields{"businesstype"} = "businesstype";
$fields{"email"} = "email";
$fields{"company"} = "company";
$fields{"designcheck"} = "designcheck";
$fields{"pages"} = "pages";
$fields{"forms"} = "forms";
$fields{"optimize"} = "optimize";
$fields{"presentsite"} = "presentsite";
$fields{"admire"} = "admire";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b)
{$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: noreply@leedoeswebsites.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else
{
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);}
}
}
?>
I admit I am a novice with php right now. My problem is with this php code that I copied from a tuitorial, and I keep getting back "You have not entered an email, please go back and try again."
I'm hoping someone would help me and I would also like to send them a successful page a thank you page too.
Regards,
Lee Frandsen posting.php?mode=post&f=1#
<style type="text/css">
#recaptcha_error_box {
width:30%;
border:medium groove #A00;
background-color:#FF9;
padding:1em;
color:#900;
font-weight:bold;
font-size:80%;}
</style>
<?php
require_once('recaptchalib.php');
$privatekey = "xxxxx";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
echo '<div id="recaptcha_error_box">The reCAPTCHA failed with this message: '.$response->error.'<br />Please try again.</div>';
} else
{
$to = $_POST['leefrand@cox.net'];
$name = $_POST['name'];
$from = $_POST['email'];
$headers = "from: $from";
$subject = "estimateform";
$fields = array();
$fields{"name"} = "name";
$fields{"phone"} = "phone";
$fields{"businesstype"} = "businesstype";
$fields{"email"} = "email";
$fields{"company"} = "company";
$fields{"designcheck"} = "designcheck";
$fields{"pages"} = "pages";
$fields{"forms"} = "forms";
$fields{"optimize"} = "optimize";
$fields{"presentsite"} = "presentsite";
$fields{"admire"} = "admire";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b)
{$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: noreply@leedoeswebsites.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else
{
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);}
}
}
?>