Page 1 of 1
information not being sent from my form
Posted: Tue Oct 06, 2009 12:49 pm
by lycialive
Hi, I'm brand new to php, and was wondering if someone could help me figure out why I'm only getting a message from the "textbox" section of my form. This is what I have so far:
If you can help, that would be great. Can you show me exactly how to put the right code in?
Thanks!
<?php
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
$address = $_REQUEST['address'] ;
$message = $_REQUEST['message'] ;
mail( "
name@email.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location:
http://webiste.com/thankyou.html" );
?>
Re: information not being sent from my form
Posted: Tue Oct 06, 2009 1:10 pm
by chopsmith
Can you post the code for the form? Also, are you getting an email sent to you that only contains the $message? If so, what else do you want it to contain?
Re: information not being sent from my form
Posted: Tue Oct 06, 2009 1:23 pm
by lycialive
Yeah, all I get is what's in the textbox $message area. I would like it to contain everything on this form. Eventually, I want to learn how to create a "quote" form which will be different fields etc., but for now, I'll take it slow since I'm just beginning. Thanks a ton!
here's the form html:
<div id="form1"><form method="post" action="sendmail.php">
<input type="hidden" name="meta_required" value="name,from,custom Business Name,custom Business Phone,custom Business Address,custom Business Owner,custom Business City,custom Business State,custom Business Zip,custom Ordered Before">
<p>Name: <input type="text" name="name" value="" size="20"><br />
Email: <input type="text" name="from" value="" size="20"><br />
Business Name:<input type="text" name="custom Business Name" value="" size="20"><br />
Phone: <input type="text" name="custom Business Phone" value="" size="20"><br />
Address: <input type="text" name="custom Business Address" value="" size="20"><br />
City: <input type="text" name="custom Business City" value="" size="20"><br />
State: <input type="text" name="custom Business State" value="" size="20"><br />
Business Zip: <input type="text" name="custom Business Zip" value="" size="20"><br />
Are you the business owner?<br />
<input type="radio" name="custom Business Owner" value="Yes"> Yes<br />
<input type="radio" name="custom Business Owner" value="No"> No<br />
Have Your Ordered From Us Before?<br />
<input type="radio" name="custom Ordered Before" value="Yes"> Yes<br />
<input type="radio" name="custom Ordered Before" value="No"> No<br /><br />
<textarea name="message" rows="15" cols="40">
</textarea><br /><br />
<input type="submit" />
</p>
</form>
</table>
</div>
Re: information not being sent from my form
Posted: Tue Oct 06, 2009 1:57 pm
by chopsmith
First, instead of using $_REQUEST, I would use $_POST, although it's not necessary. Anyway, change your script to this:
Code: Select all
<?php
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$address = $_POST['address'] ;
$message = ""; //blank message, could also start with whatever you want as first line in message
$message .= $name . "\n"; //the "\n" is for a new line, but it might show up in the message.
$message .= $email . "\n";
$message .= $phone . "\n";
$message .= $address . "\n";
$message .= $_POST['message'] ;
mail( "name@email.com", "Feedback Form Results",$message, "From: $email" );
header( "Location: http://webiste.com/thankyou.html" );
?>
See, you have to append all of the information to the $message variable (or some variable) that you are using in the mail() function. Also, I haven't added all the other variables being sent with the form, just the ones you put in your script. Hopefully, you get the idea.
Re: information not being sent from my form
Posted: Tue Oct 06, 2009 2:19 pm
by lycialive
Okay, it's still not working, but I am getting a "name" + the message which is more than I got before. So, we're probably on the right track, I just need it to send the rest of the info on the form.
Also, In my email, the sender name for the form is "nobody".
I really appreciate how you wrote it out though! That helps alot.
Re: information not being sent from my form
Posted: Tue Oct 06, 2009 2:26 pm
by Mirge
lycialive wrote:Okay, it's still not working, but I am getting a "name" + the message which is more than I got before. So, we're probably on the right track, I just need it to send the rest of the info on the form.
Also, In my email, the sender name for the form is "nobody".
I really appreciate how you wrote it out though! That helps alot.
Use the correct variables... ie:
Email: <input type="text" name="from" value="" size="20"><br />
Notice "name" is "from". So you'd use $_POST['from'] instead of $_POST['email']... rinse & repeat for the remaining form fields.
I don't personally use spaces in my names.
Re: information not being sent from my form
Posted: Wed Oct 07, 2009 10:18 am
by lycialive
It's still not pulling any info in. I ran across this on the web:
If you are receiving empty mails, it is because your server (Php-installation) has register_globals off. Use the Global variables provided by PHP which are $_POST, $_SERVER can easily be adjusted by using the globals that PHP provides, that is:
$_POST['name']
$_POST['company']
etc. for all variables of the form and
$_SERVER['HTTP_USER_AGENT']
etc. for the info that is provided by the Server.
I guess I have to go a lot deeper than I thought. I'd hate to have to resort to javascript, especially when php is supposed to be so easy, but I have to get a form going, so maybe js is the only option right now. Thanks for everything though!
Re: information not being sent from my form
Posted: Wed Oct 07, 2009 10:58 am
by Mirge
lycialive wrote:It's still not pulling any info in. I ran across this on the web:
If you are receiving empty mails, it is because your server (Php-installation) has register_globals off. Use the Global variables provided by PHP which are $_POST, $_SERVER can easily be adjusted by using the globals that PHP provides, that is:
$_POST['name']
$_POST['company']
etc. for all variables of the form and
$_SERVER['HTTP_USER_AGENT']
etc. for the info that is provided by the Server.
I guess I have to go a lot deeper than I thought. I'd hate to have to resort to javascript, especially when php is supposed to be so easy, but I have to get a form going, so maybe js is the only option right now. Thanks for everything though!
It's not hard... I explained what you did wrong & how to fix it.
Re: information not being sent from my form
Posted: Wed Oct 07, 2009 3:34 pm
by lycialive
ok, got it to work finally. The thing was that some of "name" attributes on the html form were capitalized.