0

Whenever I enter text into the textbox, it is not properly transferring to PHP. PHP reads the input as null, when in reality, there is text in there.

PHP code.

    //Two Email Lines
$email_to = "[email protected]";
$email_subject = "AUTO: REQUEST";

//Set equal to email form textbox
$email_form = $_POST['email_text'];


$email_message = "Email: " . $email_form . "";

//Create email headers
@mail($email_to, $email_subject,$email_message,$headers);

HTML code for the form

<div id="form">

<form method="post" action="Email_Form_Script.php" enctype="text/plain" onsubmit="window.open('FormPopUp.html','popup','width=500,height=500,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');" >
    <div>
        <input type="text" class="text" name="e3text" id="emailForm" value="Enter your e-mail address" onfocus="if(this.value=='Enter your e-mail address') { this.value = '' }" onblur="if(this.value=='') { this.value = 'Enter your e-mail address' }" />
        <input type="hidden" value="" name="email2"/>
        <input type="hidden" name="loc" value="en_US"/>
        <input type="submit" class="submit" value=""/></div>
</form>
</div>

Really confused as to why it is not working. I keep getting empty emails that just say " Email: " (No text after Email).

4
  • you don't have any input in html code with name email_text. i'd say that is the first problem. Commented Sep 8, 2012 at 16:49
  • Please don't drastically alter the question information (or code), other people viewing your question can't figure out what the original problem was, and the question doesn't make sense. You can add content to the original question ("EDIT: I've tried setting the field to 'e3text' but it still fails") Commented Sep 8, 2012 at 17:19
  • Well, actually I think the Dude got his answer, changed the question to be correct, and didn't care to accept any of the answers he got. Commented Sep 8, 2012 at 17:22
  • The code still has the same problem. I mistakenly copied and pasted code that was not updated. The problem was not with the variable name. Commented Sep 8, 2012 at 17:39

4 Answers 4

2

The line:

$email_form = $_POST['email_text'];

needs to match the name of the text in the form which in your case is name="e3text" so you should use:

$email_form = $_POST['e3text'];
Sign up to request clarification or add additional context in comments.

2 Comments

@Springerdude11 I am looking through your code again, and if e3text is the email address (which the javascript function seems to imply) then where is the actual text for the message body? Are you missing a textarea from your question?
e3text is part of the message body. The textbox is meant for users to enter an e-mail address to sign up for a newsletter, and then it sends the e-mail to my personal e-mail so I can add them to the list.
0

Its because your form doesn't actually contain an input element named email_text which is referenced in your PHP code. You need to structure your HTML form code to at least look like this or change your PHP code to require $_POST['e3text'].

<div id="form">
    <form method="post" action="Email_Form_Script.php" enctype="text/plain" onsubmit="window.open('FormPopUp.html','popup','width=500,height=500,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');" >
        <div>
            <input type="text" class="text" name="email_text" id="emailForm" value="Enter your e-mail address" onfocus="if(this.value=='Enter your e-mail address') { this.value = '' }" onblur="if(this.value=='') { this.value = 'Enter your e-mail address' }" />
            <input type="hidden" value="" name="email2"/>
            <input type="hidden" name="loc" value="en_US"/><input type="submit" class="submit" value="" />
        </div>
    </form>
</div>

1 Comment

Even when I cahnge it to $_POST['e3text'] I am still getting blank e-mails.
0

try this in your php code

$email_form = $_POST['e3text'];

"e3text" is the name of your text box so in php use this name

1 Comment

PHP makes use of name attributes not ids.
0

When you hit the submit button of your form, values are passed as:

name of the input field = value of the input field

Your field is name e3text - please refer to such field in your script, i.e. $_POST['e3text'].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.