'; } // Check if all of the form fields contain data before we allow it to be submitted successfully if ($contactName == "" || $contactEmail == "" || $messageSubject == "" || $messageContent == ""){ $er .= 'Your Name, E-mail, Message Subject, and Message Content cannot be left blank.
'; } // IF NO ERROR - START if ($er == ''){ // Prepare the E-mail elements to be sent $subject = $messageSubject; $message = ' ' . $siteName . ': A Contact Message ' . wordwrap($messageContent, 100) . ' '; /* * We are sending the E-mail using PHP's mail function * To make the E-mail appear more legit, we are adding several key headers * You can add additional headers later to futher customize the E-mail */ $to = $siteName . ' Contact Form <' . $siteEmail . '>'; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional Headers $headers .= 'From: ' . $contactName . ' <' . $contactEmail . '>' . "\r\n"; $headers .= 'Reply-To: ' . $contactName . ' <' . $contactEmail . '>' . "\r\n"; $headers .= 'Return-Path: ' . $contactName . ' <' . $contactEmail . '>' . "\r\n"; $headers .= 'Date: ' . date("r") . "\r\n"; $headers .= 'X-Mailer: ' . $siteName . "\r\n"; // And now, mail it if (mail($to, $subject, $message, $headers)){ echo '
Thank you for contacting ' . $siteName . '. We will read your message and contact you if necessary.
'; } else { $er .= 'We weren't able to send your message. Please contact ' . $siteEmail . '.
'; } } // IF NO ERROR - END } // If web form has not been submitted, show a blank form else { showContactForm(); } /* * If there have been errors, we want to return notification * We also want to be nice, and send any data already filled in back so they don't re-enter it */ // If there are errors, and the contact E-mail is filled in if ($er != '' && isset($_POST["contactEmail"])){ showContactForm($contactName, $contactEmail, $messageSubject, $messageContent, $er); } // If there are errors, and the contact E-mail isn't filled in else if ($er != '' && !isset($_POST["contactEmail"])){ showContactForm('', '', '', '', $er); } // Setup a function to display a contact form function showContactForm($contactName = "", $contactEmail = "", $messageSubject = "", $messageContent = "", $er = ''){ echo '
' . $er . '
'; } ?>