• 0

PHP Question


Question

Hey guys,

I've got a webpage with a form for emails and I've got the action for the form as a php page ("action=page.php"). This php page has the code to send the email. The problem is that It's not sending the information in the text fields. This is the problem area:

$from_name = $name;

$from_address = $email;

I've named the text fields on the form name and email, however, when I get the email it just has 'name' for the name etc... It's not recognizing the form names.

I'm still learning php, so any help would be great. :)

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Try this in 'page.php':

$from_name = $_REQUEST['name'];
$from_address = $_REQUEST['email'];

$_REQUEST is a global PHP var that stores any HTTP variables sent through post/get. There are actually a number of ways to send form field values through a post/get using PHP. You could even use session vars, but this way is simpler, imho.

Link to comment
Share on other sites

  • 0

Great, it worked!

Thank you RufioPan :)

Oh, and one more thing. How do I format it so I get multiple fields in my email message? At the moment I have this:

$message = $_REQUEST['comments'];

But I'm wanting to have it so it appears as:

Name: Their name

Email: Their email

Comments: Their comments.

I'm guessing it's something like:

$message = "Name: ", $_REQUEST['name'], "<br>Email: ", $_REQUEST['email'], "<br>Comments: " $_REQUEST['comments'];

I appreciate the help.

Link to comment
Share on other sites

  • 0

Close - change the commas to dots like this:

$message = "Name: " . $_REQUEST['name'] . "<br />Email: " . $_REQUEST['email'] . "<br />Comments: " . $_REQUEST['comments'];

$_REQUEST holds all the data passed to a script from POST, GET or cookies. For security you might want to get info from just one, so use:

$myvar = $_POST['myvar']; or $myvar = $HTTP_POST_VARS['myvar'];

$myvar = $_GET['myvar']; or $myvar = $HTTP_GET_VARS['myvar'];

$myvar = $_COOKIE['myvar']; or $myvar = $HTTP_COOKIE_VARS['myvar'];

The second option on each of those is longer, but I find it more reliable. I've known some server configurations to fail with the shorter $_POST array or whatever. That said, the same configs don't like $_REQUEST so it's a reasonable guess that if $_REQUEST works, so will $_POST, $_GET and $_COOKIE.

Link to comment
Share on other sites

  • 0

$_POST (short for $_HTTP_GET_POST) also does this i htink....

say the text box is called xxx then the variable on the page that you post the data to would be $_POST['xxx']

Link to comment
Share on other sites

  • 0
$message = "Name: ", $_REQUEST['name'], "<br>Email: ", $_REQUEST['email'], "<br>Comments: " $_REQUEST['comments'];

id say a easy way to do that (im going to use $_POST and not $_request)

$name = $_POST['name_form'];
$email = $_POST['email_form'];
$comments = $_POST['comments_form'];

echo "Name: $name &lt;br&gt; Email: $email &lt;br&gt; Comments: $comments &lt;br&gt; ";

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.