Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Response to Yahoo Question: http://answers.yahoo.com/question/?qid=20110712113235AAkRVNc
- */
- // Set the Timezone to your local timezone Setting.
- // To get the appropriate time listing/setting visit:
- // http://www.php.net/manual/en/timezones.php
- // Beware the the timezones are case sensitive
- date_default_timezone_set('America/New_York');
- // Functions
- function postVars(){ // Will bind all inputed values to variables with the same name
- $a = func_get_args();
- $c = func_num_args();
- $m = get_magic_quotes_gpc();
- for($i=0;$i<$c;++$i){
- Global ${$a[$i]};
- $v = trim($_POST[$a[$i]]);
- ${$a[$i]} = ($m)? stripslashes($v) : $v;
- }
- }
- function requiredEntries(){
- $a = func_get_args();
- $c = func_num_args();
- $e = Array();
- for($i=0;$i<$c;++$i){
- if(strlen(trim($_POST[$a[$i]])) === 0){
- $e[] = ucwords($a[$i]) . ' is a required field.';
- }
- }
- $c = count($e);
- if($c > 0){
- return 'The following error(s) were detected:<br />- ' . implode('<br />- ',$e) . '<br />Please correct before continueing. <a href="Javascript: history.go(-1);">Return to form</a>';
- }else{
- return true;
- }
- }
- // Check for required inputs
- $required = requiredEntries('Email','Salutation','FName','LName','Community','Address','Phone');
- if($required !== true){
- die($required);
- }
- // get posted data into local variables
- bindPostVars('Email','Salutation','FName','LName','Community','Address','Phone','Comment');
- $EmailFrom = 'maintenance@gebhartproperties.com'
- $successPage = 'success.php'; // The page to send the user to on a successful sending of the email
- $errorPage = 'errorPage.php'; // User will be sent to if the mail() function fails, not if the user inputs errored information.
- // Variable Dependents
- if($Community === 'North' || $Community === 'East'){
- $EmailTo = strtolower($Community) . 'maintenance@gebhartproperties.com';
- $Subject = $Community . ' Maintenance Request';
- }else {
- die('Invalid Community Input. <a href="Javascript: history.go(-1);">Return to form</a>');
- }
- // prepare email body text
- $body = '
- Email: ' . $Email . '
- Salutation: ' . $Salutation . '
- First Name: ' . $FName . '
- Last Name: ' . $LName . '
- Phone: ' . $Phone . '
- Community: ' . $Community . '
- Address:
- ' . $Address . '
- Comment:
- ' . $Comment . '
- Message Received: ' . date("H:i:s F n, Y") . '
- ';
- // send email & redirect to success page
- if (mail($EmailTo, $Subject, $Body, "From: Gebhart Maintenance <{$EmailFrom}>")){
- header('Location: ' . $successPage);
- }else{
- header('Location: ' . $errorPage);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement