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 = "contact@mywebsite.com";
$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).
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>
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'];
try this in your php code
$email_form = $_POST['e3text'];
"e3text" is the name of your text box so in php use this name
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']
.