Created
June 18, 2016 13:24
-
-
Save mohitesachin217/34044807037319d36adf9d1b3fa72e47 to your computer and use it in GitHub Desktop.
php email template with headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* echo "<pre>"; | |
print_r($_POST); | |
echo "</pre>";*/ | |
//ini_set('display_errors', 'On'); | |
//set_error_handler("var_dump"); | |
/** | |
* function to filter sql injections and illegal characters inside the input | |
* | |
*/ | |
function filter_vals($val){ | |
return addslashes($val); | |
} | |
/** | |
* function to convert number to day | |
*/ | |
function day($no){ | |
/*$day = array( | |
'0' => 'Sunday', | |
'1' => 'Monday', | |
'2' => 'Tuesday', | |
'3' => 'Wednesday', | |
'4' => 'Thursday', | |
'5' => 'Friday', | |
'6' => 'Saturday', | |
);*/ | |
return $no ; | |
} | |
/** | |
* | |
* set required fields here and appropriate message for each fields | |
* | |
*/ | |
$required = Array( | |
'full-name' => '<br/>Full Name field is required<br/>', | |
'email' => '<br/>Email Field is required<br/>' , | |
'mobile' => '<br/>Mobile Field is required<br/>', | |
'day' => '<br/>Day field is required<br/>', | |
'doa' => '<br/>Please select proper date of appointment<br/>', | |
'time' => '<br/>Please select proper time of appointment<br/>', | |
); | |
/** | |
* Set go back message here | |
*/ | |
$go_back = 'Please <a href="#" onClick="history.go(-1)">Click Here to go back</a><br/>'; | |
/** | |
* | |
* final settings before validation and filtering | |
*/ | |
//$_POST['full-name']=""; | |
/*echo "<pre>"; | |
print_r($_POST); | |
echo "</pre>";*/ | |
/* | |
* validation code | |
* | |
*/ | |
foreach($_POST as $key => $value){ | |
if(array_key_exists($key,$required) && $_POST[$key]=="" ){ | |
//get message | |
$message = $required[$key]; | |
echo $message.$go_back; | |
exit(); | |
}else{ | |
if( ($key=="d-saturday") && !(sat_day_validate($_POST[$key])) ){ | |
//get message | |
$message = $required[$key]; | |
echo $message.$go_back; | |
exit(); | |
} | |
//filter values | |
$_POST[$key] = filter_vals($_POST[$key]); | |
//echo "<br/>Proceed with ".$val; | |
} | |
} | |
/** | |
* Set values for the variables | |
*/ | |
$to = "[email protected]";//'[email protected]'; | |
$subject = 'Appointment Request mail'; | |
//mesage here | |
$message = ":::Candidate Details:::\n". | |
"Name: ".$_POST['full_name']."\n" | |
."Date of Birth: ".$_POST['dob']."\n" | |
."Qualification: ".$_POST['qualification']."\n" | |
."Profession: ".$_POST['profession']."\n" | |
."Email: ".$_POST['email']."\n" | |
."Mobile: ".$_POST['mobile']."\n" | |
."Address: ".$_POST['address']."\n" | |
."Day: ".day($_POST['day'])."\n" | |
."Appointment Date: ".$_POST['doa']."\n" | |
."Time: ".$_POST['time']."\n" | |
."Problem: ".$_POST['problem']."\n"; | |
/** | |
* | |
// 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 .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; | |
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; | |
$headers .= 'Cc: [email protected]' . "\r\n"; | |
$headers .= 'Bcc: [email protected]' . "\r\n"; | |
* | |
* | |
* | |
*/ | |
$From = "From: ". $_POST['name']." <".$_POST['email'].">"; | |
// Thank you message here | |
$message_thank_you = "Thank You For Contacting Us"; | |
// send the mail and show status message | |
if(mail($to, $subject, $message, $From)){ | |
echo "<script>alert('".$message_thank_you."'); | |
window.location = 'index.html'; | |
</script>"; | |
}else{ | |
echo "<script>alert('Error Sending Mail'); | |
history.go(-1); | |
</script>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment