I have a simple contact from that i wish to “POST” via a function but i cant seem to get it to work?
The form works when i have the action send to an external “send.php” file but i wish to keep everything in the one file.
<form action="send()" id="contactform" method="POST">
<p>Name<input type="text" name="name">
Email
<input type="text" name="email">
Phone
<input type="text" name="phone">
</p>
<p>Message
<textarea name="message" rows="6" cols="25"></textarea>
<br />
<input type="submit" value="Send">
</p>
</form>
<?php
function send()
{
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Email: $email \n Message: $message";
$recipient = "email@email.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
}
?>
You can’t call php code from a
<form>tag. Typically you handle this as a “postback” back to the same page, and check if a form variable is set to determine if the postback has happened:Then in your code: