How do I make an HTML FORM to work in PHP? Am new in PHP, I designed a website with a what you see is what you get software (WYSIWYG) but now I need a form in PHP, I have written the HTML form and I have put the contact PHP script as the value for the action attribute. I have also written the code for the submitted date using PHP $_GET and $_POST. My problem is getting the mail function to work. How do I send the data to the mail using the mail function?
I need help in PHP form
PHP mail() function is used to send emails in PHP. Then use the following code for mail function to keep the variables in your script and to form the website.
<?php
//if "email" variable is filled out, send email
 if (isset($_REQUEST['email'])) {
Â
 //Email information
 $admin_email = "[email protected]";
 $email = $_REQUEST['email'];
 $subject = $_REQUEST['subject'];
 $comment = $_REQUEST['comment'];
Â
 //send email
 mail($admin_email, "$subject", $comment, "From:" . $email);
Â
 //Email response
 echo "Thank you for contacting us!";
 }
Â
 //if "email" variable is not filled out, display the form
 else {
?>
Â
 <form method="post">
 Email: <input name="email" type="text" /><br />
 Subject: <input name="subject" type="text" /><br />
 Message:<br />
 <textarea name="comment" rows="15" cols="40"></textarea><br />
 <input type="submit" value="Submit" />
 </form>
Â
<?php
 }
?>
Â
In the above code, the first part checks to see whether the email is entered or not. If present, set to ready to send. After filling the email, click submit, then page gets reload and reads the email input which you have given and sends it.