I have used successfully the following php script to send mail using html form. As you can see the following script accommodates only three entries namely name, email and comments.
But when I try to increase the number of entries to say four making required changes in the script, I get nowhere. I need someone’s feedback so I can understand how to go about correcting this situation. I can upload the html form if he or she would require it.
Thanks.
Bob Ghodsi
<
Emailing Form Data code {color:#F00C4D;font-weight:bold;font-size:1.2em} i {color: #6D0CF0}.error { color: red; }
<?php
$name=$_POST[‘name’];
$email=$_POST[‘email’];
$comments=$_POST[‘comments’];
$redirectTo = “http://www.bghodsi.com”;
$to = "[email protected]";
$from = "[email protected]";
$subject = “Contact Form Submission”;
$headers = “From: $from\r\n”;
$message = “”;
$formFields = array_keys($_POST);
for ($i = 0; $i < sizeof($formFields); $i++)
{
$theField = strip_tags($formFields[$i]);
$theValue = strip_tags($_POST[$theField]);
$message .= $theField;
$message .= " = ";
$message .= $theValue;
$message .= “\n”;
}
// Check if the form has been submitted
if (isset($_POST[‘submitted’])) {
$problem = FALSE ;// No problems so far.
// Check for each field
if (empty($_POST['name'])) {
$problem = TRUE;
}
if (empty($_POST['email'])) {
$problem = TRUE;
}
if (empty($_POST['comments'])) {
$problem = TRUE;
}
if ($problem)
{
include(“oops.php”);
exit;
}
else {
$success = mail($to, $subject, $message, $headers);
include(“thanks.php”);
}
} ?>