就像我的标题所说,我的电子邮件表单在电子邮件中提交“未定义”。让我从一些代码开始......
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);
}
?>
我收到的电子邮件看起来像这样(是的,我在字段中输入了文本......):
Name: undefined
Email: undefined
Phone Model:
Comments: undefined
我注意到的第一件事:“电话模型”不像其他人那样说“未定义”。其次,为什么其他人说未定义而不是我输入的文字?
提前致谢。