I am trying to create a form on my website that sends an email to the specific email address of my choice. I also need to create a "success message" that displays when the user submits there information, but that the message simply appears under the form on the same page, and not on a new page. I had this working before, and then I had to switch the site to goDaddy and then I no longer got the success message.
I am a total novice and just need some advice to get this fixed fast.
The code is below for people to examine.
<?php
$email = 'thomas_stirling@hotmail.com'; // email who you're sending to
$subject = $_POST['subject']; //email subject
$headers = 'From: Clearly Creative Homepage Leads' . "\r\n" .
'Reply-To: thomas_stirling@hotmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = '';
$errorStr = '';
if(isset($_POST['submit'])) {
/* define required fields */
$requiredFields = array(
'Company Name' => 'companyname',
'Name' => 'name',
'EMail' => 'email',
'Message' =>'message'
);
/* valudate required fields */
foreach($requiredFields as $key => $value) {
if($_POST[$value] == '') {
$errorStr .= "Error: Field $key is required <br />";
}
}
/* if all fields validated, send the email */
if($errorStr == '') {
/* Create Message */
$messageFields = array(
'Company Name' => $_POST['companyname'],
'Name' => $_POST['name'],
'E-Mail' => $_POST['email'],
'Message' => $_POST['message']
);
foreach($messageFields as $key => $value) {
$message .= "$key : $value \n";
}
mail($email, $subject, $message, $headers);
$sent = 1;
}
}
?>
<!-- this is the form starting-->
<form action="index_sidebar_test.php" method="POST">
<font class="sidebarDate">Company Name *</font><br />
<input width="200" name="companyname" type="text"/><br />
<font class="sidebarDate">Full Name *</font><br />
<input width="200" name="name" type="text" /><br />
<font class="sidebarDate">Email Address *</font><br />
<input width="200" name="email" type="text" />
<br />
<font class="sidebarDate">Message *</font><br />
<textarea cols=20 rows=4 name="message" /></textarea>
<br /><br />
<input type="submit" value="Submit" name="submit"/></form>
<?php
if($sent == 1 && isset($_POST['submit']) ) {\
?>
<span class="Main_HeadingText">Thanks for your submission.<br />
We’ll get back to you within one business day.</span>
<?
} elseif ($errorStr != '') {
print $errorStr;
}
?>
<!-- this is the form ending -->