get and post have nothing to do with databases, it has to do with your method on your form
<form method="GET">
<form method="POST">
change your form and then change the way you retrieve the variables.
Main Topics
Browse All TopicsHi,
I am new to PHP and am having a problem with a form to email information collected from an html form. When I use the "GET" parameter, the information gets to the intended email. When I use "POST" the email returns with empty fields. Can someone describe the difference between "GET" and "POST" that would cause this? My client does not want a database on his site. Just information emailed to him from these forms. Also, I am concerned with security using "GET" where the information is shown in the URL.
Here is the code I am using with "GET" and it is working but I think "POST" is what I will need for securitiy reasons. Can you use "POST" without a database?
<?php
// variables
$customer_name = $_GET['customer_name'];
$from = $_GET['customer_email'];
$customer_phone = $_GET['customer_phone'];
$customer_comment = $_GET['customer_comment'];
//to and subject
$to = "ozzie@bclean.com";
$subject = "Customer Inquiry";
//message body
$message = '
<html>
<head>
</head>
<body>
<table width="90%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="15%" align="left" valign="top">Name:</td>
<td align="left" valign="top"><b>'.$custome
</tr>
<tr>
<td width="15%" align="left" valign="top">Email Address:</td>
<td align="left" valign="top"><b>'.$from.'<
</tr>
<tr>
<td width="15%" align="left" valign="top">Phone Number:</td>
<td align="left" valign="top"><b>'.$custome
</tr>
<tr>
<td colspan="2"><h2>How may we be of assistance?</h2></td>
</tr>
<tr>
<td colspan="2"><p>'.$customer
</tr>
</table>
</body>
</html>
';
//make sure text wraps if it is to long
$message = wordwrap($message, 70);
//set html content type
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' .$from. "\r\n";
mail($to, $subject, $message, $headers);
?>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
hi RosieisSweet,
You partially answered the question yourself, the difference between POST and get is that GET method the values are passed through the url, eg:
http://www.mydomain.com/in
in this case you can use the $_GET to get the 'myvalue', however POST will not work as POST looks for values submitted through the <form> tags, in your previous html page.
In terms of security, they are pretty much the same, no difference, one can reproduce POST submissions (by manually inserting values) as easily as GET.
Hope this helps.
Thank you for the comments but I am still confused as to why when I change this to POST, it is not forwarding the form values. Does the html form have to contain other PHP information (other than the method="POST") to get the information to forward to the action page when the submit button is clicked?
Here is the form page which uses the action code I showed above:
<form name="contact_form" id="contact_form" method="get" enctype="text/plain" action="response.php">
<table width="98%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" align="left" valign="top">Name:</td>
<td width="80%" align="left" valign="top"><input name="customer_name" type="text" id="customer_name" size="50" maxlength="60"></td>
</tr>
<tr>
<td align="left" valign="top">Email Address:</td>
<td align="left" valign="top"><input name="customer_email" type="text" id="customer_email" size="50" maxlength="60"></td>
</tr>
<tr>
<td align="left" valign="top">Phone Number:</td>
<td align="left" valign="top"><input name="customer_phone" type="text" id="customer_phone" size="15" maxlength="15"></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><img src="assets/spacerw.gif" width="1" height="12"></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><p class="supplier_link">How may we be of assistance?</p> </td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><textarea name="customer_comment" id="customer_comment" cols="75" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" id="submit" onClick="MM_validateForm('
&n
<input type="reset" name="clear_form" id="clear_form" value="Clear Form"></td>
</tr>
</table>
</form>
When I change GET to POST, the form does not send the info. I hope you can help as I am very confused at this point.
It's important to know when to use GET and when to use POST. In fact, the name says it all. You use GET to retrieve information, to "get" the information out of the database. This typically happens with search engines, or when you want to see your profile (like when you subscribe to a forum).
When you want to insert or update information that is stored in a database, like when you want to change your profile or send an (web based) email, you use POST, meaning that you "post" information to the server.
As is told already, GET parameters and values are shown in the URL. This has the advantage that you can bookmark it. So you can copy the URL of a google-search, and mail it to someone else, and it works. You don't want to do this when you edit your profile, or submit a comment on a forum. Besides that, POST values like in a forum can be long texts, hundreds of lines, and you don't want that in the URL.
Okay. I went into the form and changed it to this:
<form name="contact_form" id="contact_form" method="post" enctype="text/plain" action="response.php">
<table width="98%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" align="left" valign="top">Name:</td>
<td width="80%" align="left" valign="top"><input name="customer_name" type="text" id="customer_name" size="50" maxlength="60"></td>
</tr>
<tr>
<td align="left" valign="top">Email Address:</td>
<td align="left" valign="top"><input name="customer_email" type="text" id="customer_email" size="50" maxlength="60"></td>
</tr>
<tr>
<td align="left" valign="top">Phone Number:</td>
<td align="left" valign="top"><input name="customer_phone" type="text" id="customer_phone" size="15" maxlength="15"></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><img src="assets/spacerw.gif" width="1" height="12"></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><p class="supplier_link">How may we be of assistance?</p> </td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><textarea name="customer_comment" id="customer_comment" cols="75" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" id="submit" onClick="MM_validateForm('
<input type="reset" name="clear_form" id="clear_form" value="Clear Form"></td>
</tr>
</table>
</form>
And I changed the action form to this:
<?php
// variables
$customer_name = $_POST['customer_name'];
$from = $_POST['customer_email'];
$customer_phone = $_POST['customer_phone'];
$customer_comment = $_POST['customer_comment']
//to and subject
$to = "rsweetsprint@earthlink.ne
$subject = "Customer Inquiry";
//message body
$message = '
<html>
<head>
</head>
<body>
<table width="90%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="15%" align="left" valign="top">Name:</td>
<td align="left" valign="top"><b>'.$custome
</tr>
<tr>
<td width="15%" align="left" valign="top">Email Address:</td>
<td align="left" valign="top"><b>'.$from.'<
</tr>
<tr>
<td width="15%" align="left" valign="top">Phone Number:</td>
<td align="left" valign="top"><b>'.$custome
</tr>
<tr>
<td colspan="2"><h2>How may we be of assistance?</h2></td>
</tr>
<tr>
<td colspan="2"><p>'.$customer
</tr>
</table>
</body>
</html>
';
//make sure text wraps if it is to long
$message = wordwrap($message, 70);
//set html content type
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' .$from. "\r\n";
mail($to, $subject, $message, $headers);
?>
Now when I submit the form all the information areas (the variables) come up empty. What am I missing here?
Here is the current form code:
<form name="contact_form" id="contact_form" method="post" action="responsetest.php">
<table width="98%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" align="left" valign="top">Name:</td>
<td width="80%" align="left" valign="top"><input name="customer_name" type="text" id="customer_name" size="50" maxlength="60"></td>
</tr>
<tr>
<td align="left" valign="top">Email Address:</td>
<td align="left" valign="top"><input name="customer_email" type="text" id="customer_email" size="50" maxlength="60"></td>
</tr>
<tr>
<td align="left" valign="top">Phone Number:</td>
<td align="left" valign="top"><input name="customer_phone" type="text" id="customer_phone" size="15" maxlength="15"></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><img src="assets/spacerw.gif" width="1" height="12"></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><p class="supplier_link">How may we be of assistance?</p> </td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><textarea name="customer_comment" id="customer_comment" cols="75" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Submit Request"></td>
</tr>
</table>
</form>
Here is the code from the action page:
<?php
// variables
$cust_name = $_POST['cust_name'];
$from = $_POST['cust_email'];
$cust_phone = $_POST['cust_phone'];
$cust_comment = $_POST['cust_comment'];
//to and subject
$to = "ozzie@bclean.com";
$subject = "Customer Inquiry";
//message body
$message = '
<html>
<head>
</head>
<body>
<table width="90%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="15%" align="left" valign="top">Name:</td>
<td align="left" valign="top"><b>'.$cust_na
</tr>
<tr>
<td width="15%" align="left" valign="top">Email Address:</td>
<td align="left" valign="top"><b>'.$from.'<
</tr>
<tr>
<td width="15%" align="left" valign="top">Phone Number:</td>
<td align="left" valign="top"><b>'.$cust_ph
</tr>
<tr>
<td colspan="2"><h2>How may we be of assistance?</h2></td>
</tr>
<tr>
<td colspan="2"><p>'.$cust_com
</tr>
</table>
</body>
</html>
';
//make sure text wraps if it is to long
$message = wordwrap($message, 70);
//set html content type
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' .$from. "\r\n";
mail($to, $subject, $message, $headers);
?>
These of course are each part of a standard html page. Do you need the code for the entire form and action page including the html frame?
Your code works fine for me.
I use the file response below and get the message printed correctly.
If you still have problems. Try using "print_r($_POST);" in response.php. There you can see what's in there. Second, remove the action on the form, which will set the target page to itself. Then do a "print_r($_POST);" on that page to. That might give a picture of what gets passed and where it goes wrong..
I pasted my response file below to.
Stumbled over this btw:
http://www.theblog.ca/php5
in the code you posted just recently
your $_POST variables don't match your input names
for example
<input name="customer_name" type="text" id="customer_name" size="50" maxlength="60">
$cust_name = $_POST['cust_name'];
this will never work
your $_POST variables must match your input, select, or textarea names like this
<input name="customer_name" type="text" id="customer_name" size="50" maxlength="60">
$cust_name = $_POST['customer_name'];
I am sorry about that. I picked up an incorrect file when I posted. Here is the correct form file.
<form name="contact_form" id="contact_form" method="post" action="responsetest.php">
<table width="98%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" align="left" valign="top">Name:</td>
<td width="80%" align="left" valign="top"><input name="cust_name" type="text" id="cust_name" size="50" maxlength="60"></td>
</tr>
<tr>
<td align="left" valign="top">Email Address:</td>
<td align="left" valign="top"><input name="cust_email" type="text" id="cust_email" size="50" maxlength="60"></td>
</tr>
<tr>
<td align="left" valign="top">Phone Number:</td>
<td align="left" valign="top"><input name="cust_phone" type="text" id="cust_phone" size="15" maxlength="15"></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><img src="assets/spacerw.gif" width="1" height="12"></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><p class="supplier_link">How may we be of assistance?</p> </td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><textarea name="cust_comment" id="cust_comment" cols="75" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Submit Request"></td>
</tr>
</table>
</form>
And the correct response file.
<?php
// variables
$cust_name = $_POST['cust_name'];
$from = $_POST['cust_email'];
$cust_phone = $_POST['cust_phone'];
$cust_comment = $_POST['cust_comment'];
//to and subject
$to = "ozzie@bclean.com";
$subject = "Customer Inquiry";
//message body
$message = '
<html>
<head>
</head>
<body>
<table width="90%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="15%" align="left" valign="top">Name:</td>
<td align="left" valign="top"><b>'.$cust_na
</tr>
<tr>
<td width="15%" align="left" valign="top">Email Address:</td>
<td align="left" valign="top"><b>'.$from.'<
</tr>
<tr>
<td width="15%" align="left" valign="top">Phone Number:</td>
<td align="left" valign="top"><b>'.$cust_ph
</tr>
<tr>
<td colspan="2"><h2>How may we be of assistance?</h2></td>
</tr>
<tr>
<td colspan="2"><p>'.$cust_com
</tr>
</table>
</body>
</html>
';
//make sure text wraps if it is to long
$message = wordwrap($message, 70);
//set html content type
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' .$from. "\r\n";
mail($to, $subject, $message, $headers);
?>
I have contacted the support group at my server company and sent them the link that HeroGuran posted. I am waiting for a response from them to see if this issue is based on their server settings.
Thank you all for your patience and assistance. I will post as soon as I get a response from them.
Business Accounts
Answer for Membership
by: ZylochPosted on 2007-12-10 at 12:12:41ID: 20444636
If you want to use post, you set the form method to POST and then use $_POST instead of $_GET. Post has no restrictions on how much data you can transmit, while GET has a limit of around 256 characters or something similar to that (don't remember exactly).