473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

PHP form sends blank variables

Hi, I'm really new to PHP so please be gentle. I have created a contact form for a friend but when I submit the form - it goes to the right address but all of the variables are blank.
I'm totally stuck - can anyone help?

php code is

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $EmailFrom = "info@govandentalcare.co.uk";
  4. $EmailTo = "conniemurray1@hotmail.com";
  5. $Subject = "online form";
  6. $Name = trim(stripslashes($_POST['Name']));
  7. $Email = trim(stripslashes($_POST['Email']));
  8. $Tel = trim(stripslashes($_POST['Tel']));
  9. $Message = trim(stripslashes($_POST['Message']));
  10. // validation
  11. $validationOK=true;
  12. if (!$validationOK) {
  13.   echo "please check your details";
  14.   header("Location: http://govandentalcare.co.uk/contactjan.php");
  15.   exit;
  16. }
  17.  
  18. // prepare email body text
  19.  
  20. $Body = "";
  21. $Body .= "Name: ";
  22. $Body .= $Name;
  23. $Body .= "\n";
  24. $Body .= "Tel: ";
  25. $Body .= $Tel;
  26. $Body .= "\n";
  27. $Body .= "Email: ";
  28. $Body .= $Email;
  29. $Body .= "\n";
  30. $Body .= "Message: ";
  31. $Body .= $Message;
  32. $Body .= "\n";
  33.  
  34. // send email
  35. $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
  36.  
  37. // redirect to success page
  38. if ($success){
  39.   print "<meta http-equiv=\"refresh\" content=\"1;URL=thanks.html\">";
  40. }
  41. else{
  42.   print "<meta http-equiv=\"refresh\" content=\"1;URL=index.php\">";
  43. }
  44. ?>
Jan 3 '12 #1

✓ answered by zorgi

Now its obvious why it doesn't work.

When you submit your form with input field like this:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="email">
to retrieve submitted value in php you should do:

Expand|Select|Wrap|Line Numbers
  1. $_POST['email']
instead of

Expand|Select|Wrap|Line Numbers
  1. $_POST['Email']
input field name and $_POST key must match.

5 2031
Rabbit
12,516 Expert Mod 8TB
I don't see a form in your code.
Jan 4 '12 #2
Sorry - here's the html - thanks for any help you can give me

Expand|Select|Wrap|Line Numbers
  1.   <form action="contactjan.php" method="post">
  2.  
  3.       <p>
  4.         <input type="text" name="name" 
  5.  value="Your Name" size="20" 
  6.  onFocus="this.value=''">
  7.         <input type="text" name="email" 
  8.  value="Email Address" size="20" 
  9.  onFocus="this.value=''">
  10.         <input type="text" name="telephone" 
  11.  value="Telephone Number" size="20" 
  12.  onFocus="this.value=''">
  13.       </p>
  14.       <p>
  15.         <textarea name="message" cols="25" rows="2" onfocus="this.value=''">Your Message</textarea>
  16.       </p>
  17.       <p><br />
  18.         <input name="send" type="submit" class="formbox" id="send" value="Submit" />
  19.       </p>
  20.     </form>
  21.  
Jan 4 '12 #3
zorgi
431 Expert 256MB
Now its obvious why it doesn't work.

When you submit your form with input field like this:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="email">
to retrieve submitted value in php you should do:

Expand|Select|Wrap|Line Numbers
  1. $_POST['email']
instead of

Expand|Select|Wrap|Line Numbers
  1. $_POST['Email']
input field name and $_POST key must match.
Jan 4 '12 #4
Thanks Zorgi for your super quick response but I think I must still hjave something wrong as it's still not working - It emails back just this

name:
tel:
email:
message:


HTML is

Expand|Select|Wrap|Line Numbers
  1.   <form action="contactjan.php" method="post">
  2.   <input type="text" name="name" class="formbox" onfocus="this.value=''" value="name" />
  3.  
  4.       <input type="text" name="tel" class="formbox" onfocus="this.value=''" value="tel" />
  5.             <input type="text" name="email" class="formbox" onfocus="this.value=''" value="email" />
  6. <textarea rows="3" name="message" class="formbox" onfocus="this.value=''">message</textarea>
  7.       <p><br />
  8.         <input name="send" type="submit" class="formbox" id="send" value="Submit" />
  9.       </p>
  10.     </form>
  11.  

and PHP

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $EmailFrom = "conniemurray1@hotmail.com";
  4. $EmailTo = "conniemurray1@hotmail.com";
  5. $Subject = "contactform";
  6. $Name = Trim(stripslashes($_POST['name']));
  7. $Email = Trim(stripslashes($_POST['email']));
  8. $Tel = Trim(stripslashes($_POST['tel']));
  9. $Message = Trim(stripslashes($_POST['message']));
  10. // validation
  11. $validationOK=true;
  12. if (!$validationOK) {
  13.   echo "please check your details";
  14.   header("Location:http://govandentalcare.co.uk/contactjan.php");
  15.   exit;
  16. }
  17.  
  18. // prepare email body text
  19.  
  20. $Body = "";
  21. $Body .= "name: ";
  22. $Body .= $name;
  23. $Body .= "\n";
  24. $Body .= "tel: ";
  25. $Body .= $tel;
  26. $Body .= "\n";
  27. $Body .= "email: ";
  28. $Body .= $email;
  29. $Body .= "\n";
  30. $Body .= "message: ";
  31. $Body .= $message;
  32. $Body .= "\n";
  33.  
  34. // send email
  35. $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
  36.  
  37. // redirect to success page
  38. if ($success){
  39.   print "<meta http-equiv=\"refresh\" content=\"1;URL=thanks.html\">";
  40. }
  41. else{
  42.   print "<meta http-equiv=\"refresh\" content=\"1;URL=thanks.html\">";
  43. }
  44. ?>
  45.  
which is saved from Notepad.

Sorry to be a pain but this is driving me mad
Thanks
CX
Jan 4 '12 #5
Oh wait - now I see what you mean! Thanks so much - got it sorted and would never have managed it without your help.
Jan 4 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jerry Sievers | last post by:
Fellow coders; I am curious about a difference in behavior between Mozilla and MSIE. The scenario; 1. a php form page is loaded on first hit with field values set to various things including...
1
by: Keith | last post by:
I am Using Dreamweaver MX to create my site and have come accross a problem no one in the DW groups seems to be able to help with. When I submit an insert to my SQL database, any form value which...
2
by: Mark Hannon | last post by:
I am trying to wrap my brain around storing form elements inside variables & arrays before I move on to a more complicated project. I created this simple example to experiment and as far as I can...
2
by: JohnGates | last post by:
In VB.net, I have win form programs that do database update operations that take several minutes or longer. Several actions such as switching windows or clicking a control during these operations...
4
by: Cerebral Believer | last post by:
Hi I need help! Forgive me I am a PHP newbie. I have a small script that enables me to send a form from an HTML page. I want to use the HTML formatted form because the design of my website is...
2
by: Del | last post by:
I have a popup form that consist of a single field called EnteredBy and a Subform that has three fields. The popup form also has a button in the Form Footer called close. In the On Click event I...
1
by: simontindall | last post by:
Hi, I have an Access form that users use when logging a fault with system. The user adds the record by clicking a submit button and a table is populated with the following: - unique id of...
3
by: kronecker | last post by:
I converted a C# program to VB.Net and it compiles fine. However, when I run it I get a blank form with nothing on it. There should be a few text boxes,pull down menus etc that I put on the form...
6
by: obtrs | last post by:
i have a html form it and some php script to post it to database but every time i open page it show some error on the top but when i input data and send it it also send so how can i remove these...
1
by: metalforever | last post by:
How do you redirect a form after submit(form sends email) ? This is pretty urgent for me. I have included the code in a pastebin. http://pastebin.org/249014 process_form sends the email. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.