Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    73
    Thanks
    4
    Thanked 0 Times in 0 Posts

    $_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>");

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    What happens if you do only this ...

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

    Does it show the name from the form?

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    73
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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) { }


    ??

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • #5
    New Coder
    Join Date
    Jul 2012
    Posts
    73
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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?

  • #6
    New Coder
    Join Date
    Jul 2012
    Posts
    73
    Thanks
    4
    Thanked 0 Times in 0 Posts
    ok.. figured out..

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

    that fixed it..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •