emaiing my html form via php

Hi,
I admit I am a novice with php right now. My problem is with this 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

#recaptcha_error_box { width:30%; border:medium groove #A00; background-color:#FF9; padding:1em; color:#900; font-weight:bold; font-size:80%;}
<?php

require_once(‘recaptchalib.php’);
$privatekey = “6LcDacUSAAAAAJqFvJV5iOSsG8x6RnTLoIU6kg7s”;
$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 '

The reCAPTCHA failed with this message: '.$response->error.‘
Please try again.
’;

} else
{
$to = $_POST[‘[email protected]’];
$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: [email protected]”;
$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);}
}
}

?>

if($from == ‘’) is causing an issue here; this if statement always returns true if no value is assigned to variable $from.
Make sure a textfield named ‘email’ is existing in your form.

agreed you have to make sure that on the actual form there is a part that is something like this:
[php]

[/php]
if you do not have an input named email you will never send email post data to this script

Thanks for your replies,
I do have a requirement for email on my form. ie:

*email

I’m still wondering what the problem is.
regards,
Lee Frandsen

Hi lee,

For troubleshooting purposes, kindly echo your $from and let us know if it gets printed…

:slight_smile:

Ok, let me see if I can.

OK, I echo’d $from and got the following error:
Parse error: syntax error, unexpected T_VARIABLE, expecting ‘,’ or ‘;’
Can you make anything out of that?
lee

I echo’d $from; because last time I left off the semi-colon http://www.phphelp.com/forum/Smileys/solosmileys/embarrassed.gif
This time I got the same error message: “You have not entered an email, please go back and try again.”
For some reason it’s looping back up to if($from == ‘’)

well I just noticed one thing that is suspect:
[php]
$to = $_POST[‘[email protected]’];
[/php]

I am thinking it should just be

[php]
$to="[email protected]";
[/php] ;D

so I used most of your code and created a simple form, I got rid of the recpaptcha part because I did not have that and the following form worked:
[php]

#recaptcha_error_box { width:30%; border:medium groove #A00; background-color:#FF9; padding:1em; color:#900; font-weight:bold; font-size:80%;} <?php $to = "[email protected]"; $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: [email protected]"; $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);} } ?> name phone businesstype email company designcheck pages forms optimize presentise admire [/php] So use that as an example to setting yours up. a good way to see what is actually being post from your form is download effetech http sniffer, click the green button to start it, then click send on your form once it is all filled in, then in effectech click the red button to stop it then click on the url that you see in the big panel, then in the lower left is a smaller panel you can scroll to the bottom of that and it will show you exactly what was sent from the form, this is a good way to trouble shoot your forms and make sure the proper data is being sent, or in the actual php you can write print_r($_POST);and it will show you everything that is being posted. Hope this helps

Ok, I’ll take your advice. And thank you for all the help given. It’s greatly appreciated. Now let me see if I can get it to work on my Fatcow server.
Regards,
Lee
ps. I may be back, but I hope it’s not because of this issue.

Sponsor our Newsletter | Privacy Policy | Terms of Service