Like my title says, my email form is submitting “undefined” within the email. Let me start off with some code…
HTML:
<form action="contactform.php" method="post" enctype="multipart/form-data" name="contact">
<input name="name" type="text" value="Name" onfocus="if(this.value=='Name') this.value='';" />
<input name="email" type="text" value="Email address" onfocus="if(this.value=='Email address') this.value='';" />
<input name="phonemodel" type="text" value="Phone model" onfocus="if(this.value=='Phone model') this.value='';" />
<textarea name="comments" cols="" rows="" style="height:130px;" onfocus="if(this.value=='Type your message here.') this.value='';" >Type your message here.</textarea>
<input type="image" name="button" value="Submit" src="../media/btn_play_submit.png" style="margin-right:5px; margin-top:12px;" />
</form>
PHP:
<?php
if(isset($_POST['name'])) {
$to = 'MYEMAILHERE';
$headers = "From: blahblahblah\r\n";
$subject = "Online Contact Submission Received\r\n";
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phonemodel'];
$comments = $_POST['comments'];
$message .= "Name: " . $name . "\r\n";
$message .= "Email: " . $email . "\r\n";
$message .= "Phone Model: " . $phone . "\r\n";
$message .= "Comments: " . $comments . "\r\n";
mail($to, $subject, $message, $headers);
}
?>
The email that I receive looks like this (and yes, I’m putting text in the fields…):
Name: undefined
Email: undefined
Phone Model:
Comments: undefined
First thing I notice: the “Phone Model” does not say “undefined” like the others. Second, why are the others saying undefined instead of the text I put in?
Thanks in advance.
Fixed it. Turns out it was going through some jQuery and then AJAX before getting to the PHP which is what was causing all of my problems.
This is what happens when you get thrown into a project and don’t quite understand it. :/
Thanks everyone.