Create an HTML form that works for the following php file. Email $formEmailAddress "; echo "Topic $formTopic "; ?> contact form response This page was created by PHP on the server and sent back to your browser. "; //It will create a table and display one set of name value pairs per row echo ""; echo "Field NameValue of field"; foreach($_POST as $key => $value) { echo ''; echo '',$key,''; echo '',$value,''; echo ""; } echo ""; echo " "; $toEmail = "email"; //will send the email to the email address entered on the form $subject = "Thank you for your message. I will contact you soon."; //This is the message that will be sent back to the person who sent you a message from your contact form. $fromEmail = "address"; $emailBody = "Form Data\n\n "; foreach($_POST as $key => $value) { $emailBody.= $key."=".$value."\n"; //Adds the name value pairs to the body of the email, each one on their own line } echo "$emailBody"; $headers = "From: $fromEmail" . "\r\n"; //Creates the From header with the appropriate address if (mail($toEmail,$subject,$emailBody,$headers)) //puts pieces together and sends the email to your hosting account's smtp (email) server { echo("Message successfully sent!"); } else { echo("Message delivery failed..."); } ?>
<?php
$formEmailAddress = $_POST['email']; //pull email address from the form data
$formTopic = $_POST['topic']; //pull topic from the form data
echo "<h1>Email $formEmailAddress </h1>";
echo "<h1>Topic $formTopic </h1>";
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>contact form response</title>
<style type="text/css">
#container {
width: 800px;
border: 1px solid black;
padding: 10px;
margin: 10px auto;
}
.colorRed {
color: #F00;
}
</style>
</head>
<body>
<div id="container">
<hr>
<p> </p>
<?php
echo "<p class='colorRed'>This page was created by PHP on the server and sent back to your browser. </p>";
//It will create a table and display one set of name value pairs per row
echo "<table border='1'>";
echo "<tr><th>Field Name</th><th>Value of field</th></tr>";
foreach($_POST as $key => $value)
{
echo '<tr class=colorRow>';
echo '<td>',$key,'</td>';
echo '<td>',$value,'</td>';
echo "</tr>";
}
echo "</table>";
echo "<p> </p>";
$toEmail = "email"; //will send the email to the email address entered on the form
$subject = "Thank you for your message. I will contact you soon."; //This is the message that will be sent back to the person who sent you a message from your contact form.
$fromEmail = "address";
$emailBody = "Form Data\n\n ";
foreach($_POST as $key => $value)
{
$emailBody.= $key."=".$value."\n"; //Adds the name value pairs to the body of the email, each one on their own line
}
echo "<h2>$emailBody</h2>";
$headers = "From: $fromEmail" . "\r\n"; //Creates the From header with the appropriate address
if (mail($toEmail,$subject,$emailBody,$headers)) //puts pieces together and sends the email to your hosting account's smtp (email) server
{
echo("<p>Message successfully sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
?>
</body>
</html>
Step by step
Solved in 2 steps