3

I am trying to get my website to submit an email every time someone would message (right now I'm just working on getting my variables to work...). It's a learning process so I'm here for it all and just trying to teach myself. However non of the GLOBAL php commands like $_post and $_get are working. I even tried different ways but to no avail.

<?php
$person = $_Post['pName'];
echo "before";
echo $person;
echo "after";
echo $_Get['pName'];
?>

but this never submitted anything. My form has the method="post" and the action="TestSend.php". Yes the file name is TestSend.php too. Also, the php DOES display the "beforeafter" in the browser after I click "Submit" on my website.

If you want to test it yourself it is on my website at www.turnedbrigade.com.
One last question, do I need the html tag and the body tag with my php file?

Here's the html coding.

<form action="TestSend.php" method="post">
Name: <input name="pName" type="text" placeholder="Name"/>
Email: <input name="pEmail" placeholder="Email"/><br/>
Message: <br/><textarea name="pMessage" rows="8" cols="60" placeholder="Message"></textarea><br/>
<input type="submit"/>              
</form>

Edited:

<?php
$from =  $_POST['pName'];
$email = $_POST['pEmail'];
$subject = "Forums";
$message = $_POST['pMessage'];
mail("email will go here", $subject, $message, $from);
?>

For this email part of it, my page just goes blank and I never get anything posted past it.

HTML

HTML http://img716.imageshack.us/img716/6872/c7a3.png PHP

Php

2 Answers2

4

$_POST and $_GET is the correct variable names, they are part of the superglobals family. Php is case sensitive so you really need to use capital letters, so change

$person = $_POST['pName'];

And

echo $_GET['pName'];
Fabio
  • 23,183
  • 12
  • 55
  • 64
2

Try with $_GET and $_POST. Not sure where did you see them not capitalized ever...

And to answer your other question, if you're not planning to render the page (show it in the browser), but only do some database communication, sending email, etc... you don't need any HTML. However, all your pages that will show in the browser (the form, the 'thank you' page, etc.), they need to have a proper HTML structure. It doesn't matter you're using PHP inside of them, they are still rendered as HTML in the end.

You might notice that the pages might work even without the proper HTML structure (so no doctype, no html, head, body...), but don't ever use that. Apart from being a horrible practice, it's actually your browser taking care of your bad HTML for you, and you should never, ever rely on that. Read about how proper HTML is written (there are millions of tutorials), and use it properly.

UPDATE

For your latest update, it's normal that the page is blank - you're not outputting anything. Try changing your mail line:

mail("email will go here", $subject, $message, $from);

to something like this:

if (mail("email will go here", $subject, $message, $from)) {
    echo 'Yay! Email sent!';
}
else {
    echo 'There is an error somewhere, email not sent!';
}

And you'll see that the code is working fine.

Shomz
  • 37,421
  • 4
  • 57
  • 85
  • I also have another question about the new email section of my php that I added into the question. – TurnedTurquoise Mar 07 '14 at 00:07
  • Yup, just answered it. What do you want to show after you submit the form? Also, is that the whole TestSend page? – Shomz Mar 07 '14 at 00:08
  • See when I input all of the material and try to make it work. I still only get a blank page. – TurnedTurquoise Mar 07 '14 at 00:11
  • Even with the example I gave you? Do you have anything else on that page? – Shomz Mar 07 '14 at 00:12
  • 2
    @TurnedTorquise i think you should not edit your question after your problem was solved and add other further problems, you should instead accept the answer that more helped you out and post a new question with your new scenario. As far this should be how stackoverflow works, this is not meant to be a forum or similar – Fabio Mar 07 '14 at 00:15
  • Yes, @Fabio is right, it's hard for us to keep track of all your changes. Anyway, try that last example I gave you and see what happens. If you wish to show something like a thank you page, you can either do a redirection, or show the content on the same TestSend page... you can also use the if-clause to show different pages, too many options and we don't know what you really want to do here, ok? – Shomz Mar 07 '14 at 00:17
  • @TurnedTurquoise It's ok, that's just the way it is, so accept the answer you like more and move on to another question ;) – Fabio Mar 07 '14 at 00:18
  • I'm almost tempted to do a rollback on OP's question. – Funk Forty Niner Mar 07 '14 at 00:19
  • @Shomz alright, thank you. I gave images in the edit as it shows the html and php of the page and that's all. – TurnedTurquoise Mar 07 '14 at 00:19
  • @Fred-ii- Haha, I think you should leave it as it is now. I tried to address all the changes I could catch. – Shomz Mar 07 '14 at 00:20
  • @TurnedTurquoise You're welcome! The code looks ok, except for the from field (read about PHP's mail function). I'm not sure if that second image is what's rendered in the browser or just some editor. If so, your PHP pages are not being parsed and you should read about setting up Apache and PHP... You have things like XAMP, WAMP, MAMP, LAMP... (based on the system you're using) – Shomz Mar 07 '14 at 00:22
  • The OP's `$from` is obviously incorrect (for one thing). The plot always thickens "after the fact", which is "a" reason why I don't put in answers for questions like these. @Shomz - They always open up a "can of worms", as I call them. ;-) – Funk Forty Niner Mar 07 '14 at 00:23
  • @Shomz it's what's on my cPanel "code edit" to change my coding. – TurnedTurquoise Mar 07 '14 at 00:24
  • 1
    @Fred-ii- Right, no more answers here. – Shomz Mar 07 '14 at 00:24
  • @TurnedTurquoise Then it's fine from the code standpoint... You still have a few things to fix/add. – Shomz Mar 07 '14 at 00:26