I have this form which submits to the database, now I also want it to send an email of the form results to both the user and the administrator. This is were I get stuck as I am not too sure if I am doing it properly.
if(isset($_POST['submit'])){// handle the form
// Connect to the database.
require_once ('incl/mysql_connect.php');
// Check for a username.
// Check for a screen name.
if (eregi ("^[[:alnum:]_]{4,50}$", stripslashes(trim($_POST['user_sn'])))) {
$an = escape_data($_POST['user_sn']);
} else {
$an = FALSE;
echo '<p>Please enter a valid character name!</p>';
}
// Check for an email address.
if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['user_email'])))) {
$e = escape_data($_POST['user_email']);
} else {
$e = FALSE;
echo '<p>Please enter a valid email address!</p>';
}
// Check for a username.
if ($an && $e) { // If everything's OK.
// Make sure the username is available.
$query = "SELECT user_id FROM user WHERE user_name='$u'";
$result = @mysql_query ($query);
if (mysql_num_rows($result) == 0) { // Available.
// Add the user.
$query = "INSERT INTO user (user_name, user_sn, user_mun, user_email, user_race, user_spec, user_nature, user_cause, user_kingdom, user_find, user_recruit, user_signat, registration) VALUES ('$user_name', '$an', '$user_mun', '$e', '$user_race', '$user_spec', '$user_nature', '$user_cause', '$user_kingdom', '$user_find', '$user_recruit', '$user_signat', NOW() )";
$result = @mysql_query ($query)or die ("could not execute query."); // Run the query.
// Add the user_id.
if ($result) { // If it ran OK.
// Send an email, if desired. Spot of trouble. Is this were the email terms go?
echo 'Thank you for registering! Your confirmation email will arrive shortly.';
include ('incl/footer.html'); // Include the HTML footer.
exit();
} else { // If it did not run OK.
// Send a message to the error log, if desired.
echo '<p>You could not be registered due to a system error. We apologize for any inconvenience.</p>';
}
} else { // The username is not available.
echo '<p>That username is already taken.</p>';
}
mysql_close(); // Close the database connection.
} else { // If one of the data tests failed.
echo '<p>Please try again.</p>';
}
} // End of the main Submit conditional.