hey everyone. i pieced this together from examples and what not, i’m by no means a pro here. the only thing i changed was the result display. before it was exiting the page, so i changed it to display on the page itself.
i’d like to set the name, email, message fields as required and also add in a non-required phone number field but im at a loss as to how i can correctly put it together. any help or suggestions would be greatly appreciated.
[php]<?php
// config
$emailAddresses = array(
‘Sales’=>‘[email protected]’,
‘Advertising’=>‘[email protected]’,
);
$emailSubject = ‘Message From The Contact Page!’;
// If we are dealing with a form submission, send an email
if (isset($_POST[‘name’])) {
// Check all the fields are present
if (!isset($_POST[‘destemail’],$_POST[‘comment’],$_POST[‘srcemail’])) {
exit(“Sorry, at least one of the fields is empty.”);
}
// Check the email selected is valid
if (!isset($emailAddresses[$_POST[‘destemail’]])) {
exit(“Sorry, you have selected an invalid email option.”);
}
// Create the body of the email message
$emailBody = “{$_POST[‘destemail’]}\n\n{$_POST[‘name’]} ({$_POST[‘srcemail’]}) said:\n\n{$_POST[‘comment’]}”;
// Send the email and report the result
if (mail($emailAddresses[$_POST[‘destemail’]],$emailSubject,$emailBody,“From: {$_POST[‘srcemail’]}”)) {
$result = ‘’;
$results .= “
} else {
$results .= “
}
}
// Output the html form
?>[/php]