I have an issue with sending data to my email of my php page and another thing i need help is when a user click submit i want them to see a page saying successfully sent.
Here is the php side;
<?
// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
// Each time there?s an error, add an error message to the error array
// using the field name as the key.
if ($_POST['firstname']=='')
$arrErrors['firstname'] = 'Please provide your first name.';
if ($_POST['lastname']=='')
$arrErrors['lastname'] = 'Please provide your last name.';
if ($_POST['email']=='')
$arrErrors['email'] = 'A valid email address is required.';
if ($_POST['subject']=='')
$arrErrors['subject'] = 'Please enter a subject.';
if ($_POST['message']=='')
$arrErrors['message'] = 'Please enter content in the message box.';
if (count($arrErrors) == 0) {
// If the error array is empty, there were no errors.
// Insert form processing here.
} else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p>Please check the following and try again:</p><ol>';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</ol></div>';
}
}
?>
Here is the html code;
<fieldset id="emailform">
<p class="center"> If you want to contact me for anything regarding my site or any jobs that you need to be done. Please fill the form below and I will get back with you within 24 hours or less.</p>
<?php echo $strError; ?>
<form method="post" action="contact.html">
<!--
For every form field, we do the following...
Check to see if there?s an error message for this form field. If there is,
add the formerror class to the surrounding paragraph block. The formerror
class contains the highlighted box.
-->
<p<?php if (!empty($arrErrors['firstname'])) echo ' class="formerrorl"'; ?>>
<label for="firstname">* First Name:</label>
<input name="firstname" type="text" id="firstname" size="30" value="<?php echo $_POST['firstname'] ?>">
</p>
<p<?php if (!empty($arrErrors['lastname'])) echo ' class="formerrorl"'; ?>>
<label for="lastname">* Last Name:</label>
<input name="lastname" type="text" id="lastname" size="30" value="<?php echo $_POST['lastname'] ?>">
</p>
<p<?php if (!empty($arrErrors['email'])) echo ' class="formerrorl"'; ?>>
<label for="email">* Email Address:</label>
<input name="email" type="text" id="email" size="30" value="<?php echo $_POST['email'] ?>">
</p>
<p>
<label>Website URL:</label>
<input type="text" name="web" size="30" id="web" value="http://" />
</p>
<p<?php if (!empty($arrErrors['subject'])) echo ' class="formerrorl"'; ?>>
<label for="subject">* Subject:</label>
<input name="subject" type="text" id="subject" size="30" value="<?php echo $_POST['subject'] ?>">
</p>
<p<?php if (!empty($arrErrors['message'])) echo ' class="formerrorl"'; ?>>
<label for="message">* Message:</label>
<br />
<textarea rows="10" name="message" cols="85" id="message" value="<?php echo $_POST['message'] ?>"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit"> <input type="reset" name="Reset" value="Reset">
</p>
</form>
<div class="italic">* required</div>
</fieldset>
Here is the page where the submit button goes to;
<?php
if(isset($_POST['submit']))
{
$to = "myemail@name.com";
$subject = "Submission Form";
$fname_field = $_POST['firstname'];
$lname_field = $_POST['lastname'];
$email_field = $_POST['email'];
$web_field = $_POST['web'];
$subject_field = $_POST['subject'];
$message = $_POST['message'];
$body = " First Name: $fname_field\n Last Name: $lname_field\n E-Mail Address: $email_field\n Website URL: $web_field\n Subject: $subject_field\n Message: $message\n";
echo "<center>The message was sent successfully!</center>";
mail($to, $subject, $body);
}
else
{
echo "<center>Error Try Again!</center>";
}
?>
Any help would be appreciated!
KashMoney