Explain how to mail the content of a form.
Below is the code:
The HTML code can call the samplemail.php page and use the POST method to post the data. “POST” in the Method window indicates that the information in the form will be passed to the program processing the form.
<form action=’samplemail.php' method='post'>
Email: <input type='text' name='email'><br>
Mail body: <textarea name='body'></textarea><br>
<input type='submit' value='Send comments'>
</form>
sampleemail.php (1)
<?php
$to = sample@sample.com;
$subject = "Email from Form";
$message = $_REQUEST["body"];
$email = $_REQUEST["email"];
$headers = "From: $email";
mail($to, $subject, $message, $headers);
echo "Thanks for submitting.";
?>
Explain how to mail the content of a form.
The following is the process to mail the content of a form:
- Create a HTML form. Set the action attribute to a php file , say mailcontent.php
- Make sure that from address, to address, subject and message is properly keyed in
- Assign the corresponding form values in variables , say $email, $subject, $message etc.
- Use the function mail() to send the mail of the available values in variables
Example:mail("receipient@sample.com","Subject:$subject", $message,"From:$email");