Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-02-2013, 06:21 PM   PM User | #1
stevenryals
New Coder

 
Join Date: Jul 2012
Posts: 63
Thanks: 4
Thanked 0 Times in 0 Posts
stevenryals is an unknown quantity at this point
$_POST not working

Trying to send an email via a form post

using firebug, i could see the posted data coming across 100%..

here's the code for my php file that i'm posting the data to:

name, phone, email, company & comment all coming through the post 100% clean.. just can't seem to get the values into my variables..
doing a var_dump comes back NULL...

Code:
 
        $email_to = "email@email.com";
	$email_subject = "New Contact From **.COM";
	$name = $_POST['name']; 
	$phone = $_POST['phone']; 
	$email = $_POST['email']; 
	$company = $_POST['company'];
	$comment = $_POST['comment']; 
	$email_message = "Form details below.\n\n";
	$email_message .= "Name: ".$name."\n";
	$email_message .= "Phone #: ".$phone."\n";
	$email_message .= "Email: ".$email."\n";
	$email_message .= "Company: ".$company."\n";
	$email_message .= "Comment: ".$comment."\n";

		if (mail($email_to, $email_subject, $email_message)) {
		echo("<p>Message successfully sent!</p>");
		}
		else ("<p>Message delivery failed...</p>");
stevenryals is offline   Reply With Quote
Old 01-02-2013, 08:05 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,056
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
What happens if you do only this ...

<?php
$name = $_POST['name'];
echo "Name: ".$name;
?>

Does it show the name from the form?
mlseim is offline   Reply With Quote
Old 01-02-2013, 08:23 PM   PM User | #3
stevenryals
New Coder

 
Join Date: Jul 2012
Posts: 63
Thanks: 4
Thanked 0 Times in 0 Posts
stevenryals is an unknown quantity at this point
Quote:
Originally Posted by mlseim View Post
What happens if you do only this ...

<?php
$name = $_POST['name'];
echo "Name: ".$name;
?>

Does it show the name from the form?
no.. it sure doesn't..

here is the post from firebug:

name=TEST
phone=ING
email=MAIL
company=FORM
comment=commentboxblahblahblah

when i do a var_dump($_POST); i get:
array(0) { }


??
stevenryals is offline   Reply With Quote
Old 01-02-2013, 08:38 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Silly question: you are using method "post" rather than "get"..?
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 01-02-2013, 08:43 PM   PM User | #5
stevenryals
New Coder

 
Join Date: Jul 2012
Posts: 63
Thanks: 4
Thanked 0 Times in 0 Posts
stevenryals is an unknown quantity at this point
Yes, I am.

Now, this is very interesting indeed.. i've added this to the file:

Code:
print "CONTENT_TYPE: " . $_SERVER['CONTENT_TYPE'] . "<BR />";
$data = file_get_contents('php://input');
print "DATA: <pre>";
var_dump($data);
var_dump($_POST);
print "</pre>";
and I get this:

Code:
CONTENT_TYPE: text/plain
DATA:

string(71) "name=TEST
phone=ING
email=MAIL
company=FORM
comment=commentboxblahblahblah
"
array(0) {
}
so using php://input works just fine, but the post is not finding the values...

thoughts?
stevenryals is offline   Reply With Quote
Old 01-02-2013, 10:00 PM   PM User | #6
stevenryals
New Coder

 
Join Date: Jul 2012
Posts: 63
Thanks: 4
Thanked 0 Times in 0 Posts
stevenryals is an unknown quantity at this point
ok.. figured out..

it was sending content type plain/text
had to change to application/x-www-form-urlencoded...

that fixed it..
stevenryals is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:59 AM.


Advertisement
Log in to turn off these ads.