for examples on how to use this feature.
$subjects=array("Department 1", "Department 2", "Department 3");
// This is an array of the email addresses for the array above. There must be an email FOR EACH
// array value specified above. You can have only 1 department if you want.
// YOU MUST HAVE THE SAME AMMOUNT OF $subjects and $emails or this WILL NOT work correctly!
// The emails also must be in order for what you specify above!
// Seperate email addresses by a comma to send an email to multiple addresses.
$emails=array("dept_1@domain.com", "dept_2@domain.com", "dept_3@domain.com");
// This is the message that is sent after the email has been sent. You can use html here.
// If you want to redirect users to another page on your website use this:
//
$thanksmessage="Thank you! Your email has been sent, we will respond shortly.";
/*
//================================================================================
* ! ATTENTION !
//================================================================================
: Don't edit below this line.
*/
// Function to get the extension of the uploaded file.
function get_ext($key) {
$key=strtolower(substr(strrchr($key, "."), 1));
$key=str_replace("jpeg", "jpg", $key);
return $key;
}
// Function used to attach files to the message
function phattach($file, $name, $boundary) {
$fp=fopen($file, "r");
$str=fread($fp, filesize($file));
$str=chunk_split(base64_encode($str));
$message="--".$boundary."\n";
$message.="Content-Type: application/octet-stream; name=\"".$name."\"\n";
$message.="Content-disposition: attachment; filename=\"".$name."\"\n";
$message.="Content-Transfer-Encoding: base64\n";
$message.="\n";
$message.="$str\n";
$message.="\n";
return $message;
}
//Little bit of security from people forging headers. People are mean sometimes :(
function clean_msg($key) {
$key=str_replace("\r", "", $key);
$key=str_replace("\n", "", $key);
$find=array(
"/bcc\:/i",
"/Content\-Type\:/i",
"/Mime\-Type\:/i",
"/cc\:/i",
"/to\:/i"
);
$key=preg_replace($find, "", $key);
return $key;
}
// Initilize some variables
$error="";
$sent_mail=false;
// When the form is submitted
If($_POST['submit']==true) {
extract($_POST, EXTR_SKIP);
// Check the form for errors
If(trim($yourname)=="") {
$error.="You did not enter your name! ";
}
If(trim($youremail)=="") {
$error.="You did not enter your email! ";
} Elseif(!preg_match("/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/", $youremail)) {
$error.="Invalid email address. ";
}
If(trim($emailsubject)=="") {
$emailsubject=$defaultsubject;
}
If(trim($yourmessage)=="") {
$error.="You did not enter a message! ";
}
// Verify Attchment info
If($allowattach > 0) {
// Get the total size of all uploaded files
If((array_sum($_FILES['attachment']['size'])) > ($max_file_total*1024)) {
$error.="The max size allowed for all your files is ".$max_file_total."kb ";
} Else {
//Loop through each of the files
For($i=0; $i <= $allowattach-1; $i++) {
If($_FILES['attachment']['name'][$i]) {
//Check if the file type uploaded is a valid file type.
If(!in_array(get_ext($_FILES['attachment']['name'][$i]), $allowtypes)) {
$error.= "Invalid file type for your file: ".$_FILES['attachment']['name'][$i]." ";
//Check the size of each file
} Elseif(($_FILES['attachment']['size'][$i]) > ($max_file_size*1024)) {
$error.= "Your file: ".$_FILES['attachment']['name'][$i]." is to big. ";
} // If in_array
} // If Files
} // For
} // Else array_sum($_FILES['attachment']['size'])
} // If Allowattach
If($error) {
$display_message=$error;
} Else {
If($use_subject_drop AND is_array($subjects) AND is_array($emails)) {
$subject_count=count($subjects);
$email_count=count($emails);
If($subject_count==$email_count) {
$myemail=$emails[$emailsubject];
$emailsubject=$subjects[$emailsubject];
} // If $subject_count
} // If $use_subject_drop
$boundary=md5(uniqid(time()));
//Headers
$headers="Return-Path: <".clean_msg($youremail).">\n";
$headers.="From: ".clean_msg($yourname)." <".clean_msg($youremail).">\n";
$headers.="X-Mailer: PHP/".phpversion()."\n";
$headers.="X-Sender: ".$_SERVER['REMOTE_ADDR']."\n";
$headers.="X-Priority: ".$priority."\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
$headers.="This is a multi-part message in MIME format.\n";
//Message
$message = "--".$boundary."\n";
$message.="Content-Type: text/html; charset=\"iso-8859-1\"\n";
$message.="Content-Transfer-Encoding: quoted-printable\n";
$message.="\n";
$message.=clean_msg(nl2br(strip_tags($yourmessage)));
$message.="\n";
//Add attachments to message
If($allowattach > 0) {
For($i=0; $i <= $allowattach-1; $i++) {
If($_FILES['attachment']['tmp_name'][$i]) {
$message.=phattach($_FILES['attachment']['tmp_name'][$i], $_FILES['attachment']['name'][$i], $boundary);
} //If $_FILES['attachment']['name'][$i]
} //For
} // If
// End the message
$message.="--".$boundary."--\n";
// Send the completed message
If(!mail($myemail, clean_msg($emailsubject), $message, $headers)) {
Exit("An error has occured, please report this to the website administrator.\n");
} Else {
$sent_mail=true;
}
} // Else
} // $_POST
/*
//================================================================================
* Start the form layout
//================================================================================
:- Use the html below to customize the form.
*/
?>
Balajee Academy of Talents
ACADEMY OF FILM & TV SERIAL ACTING, MODELING, DANCE, MUSIC VOCAL