I've been figuring out what's wrong with my code. I keep getting $_POST
not working. This is my HTML code:
<form id="EmailForm" action="mailForm.php" method="post"
onsubmit="validateForm()" enctype="text/plain">
<div>
Name: <input type="text" value="" name="name" size="30" />
Email: <input type="text" value="" name="email" size="30" />
Subject: <input type="text" value="" name="subject" size="60" />
Message: <br />
<textarea name="message" rows="5" cols="60"></textarea>
<input type="submit" value="Send" />
</div>
</form>
This is my mailForm.php
code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$mailsent = mail("admin@example.com", "$subject", "$message
$name
$email", "");
if ($mailsent) {
echo ("Your email has been sent. Thank you for using our mail form. <br />");
echo ("Name: ".$name."<br />");
echo ("Email: ".$email."<br />");
echo ("Subject: ".$subject."<br />");
echo ("Message: ".$message);
}
?>
So far, I can get emails sent but all emails are empty. The name or email didn't show up, but get changed to the default name from the web hosting service. No name, no email, no subject, no message. At the mailForm.php
, I got the following only:
Your email has been sent. Thank you for using our mail form.
Name:
Email:
Subject:
Message:
I've tried echo $_POST["name"]; echo $_POST["email"]
but got empty page.