HTML and PHP message form
430
I'm currently working on a HTML form that uses PHP to send a message to email. I'm testing in MAMP and am unable to get a response after clicking "send message". Any advice would be much appreciated.
HTML
<form action="mail.php" method="POST">
<div >
<div >
<input type="text" name="name" placeholder="Name" />
</div>
<div >
<input type="text" name="email" placeholder="Email" />
</div>
</div>
<div >
<div >
<textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
<br />
</div>
</div>
<div >
<div >
<ul >
<li input type="submit" value="Submit">Send Message</li>
</ul>
</div>
</div>
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$to = '[email protected]';
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$send_message=mail($to, $subject, $formcontent, $mailheader);
if($send_message){
echo "thank you"
} else {
echo "error";
}
?>
Thanks
Answer
Solution:
found some errors in ur code
correct this:
to
correct this:
to
echo "thank you";
Answer
Solution:
Are you checking this in your local server? php mail() function may probably not work in local servers.Check it in some online servers(after correcting the bugs mentioned by @Ashish ).
Answer
Solution:
HTML
*Use Name Attribute *
PHP
Try this code.