= 4.1.2! # 2) This script expects its name to be "email_basic.php". # 3) Your "mail" function settings must be set properly! This program uses the #php "mail" function, which requires the use of sendmail (on Unix) and SMTP (on Windows)! # 4) You should have a directory specified where php stores file #attachments temporarily. When this script terminates, the attachments #should be automatically deleted from your system. # #ADDITIONAL FEATURES: # 1) Dynamically specify the "subject" field through the query string. For example: #http://www.yourdomain.com/cgi-bin/email_advanced.php?subject=hello_world #will cause the phrase "hello_world" to automatically show up as the subject for the email # 2) Dynamically specify the "to" field through the query string. For example: #http://www.yourdomain.com/cgi-bin/email_advanced.php?to=someone@somewhere.com #will cause the email to override the default destination address. Great feature if you need #to send a certain form submittal to another email address # 3) Dynamically specify the "from" field through the query string. For example: #http://www.yourdomain.com/cgi-bin/email_advanced.php?from=webmaster@thiscomputer.com #will cause the email to override the default from address. Great feature if you want #the email to come "from" another email address # 4) Any combination of the above. For example: #http://www.yourdomain.com/cgi-bin/email_advanced.php?subject=hello&from=webmaster@thiscomputer.com # 5) Multiple file attachments. The ability to add multiple file attachments instead of just one # 6) Limit the file upload size. Can specify if there are any limitations to the file upload size, and #if so, how big the allowed files are to be. # 7) Style sheets. The ability to set (or link in) style sheet definitions to customize your #HTML text to look like it does on the rest of your site! # 8) Restrict file uploads by file type! Choose which extensions you want to allow to be uploaded! # #### # If you want any of these additional features, you need to purchase the "advanced" version #of this email script. Go to http://www.davelozinski.com/scripts/email for the juicy details. :) #### # # Finally, this "basic" code is free, and comes with absolutely NO #warranties, either expressed or implied. Feel free to do what you want #with it. Feel free to build upon it. If you did not get this code #from http://www.davelozinski.com, you don't have the original. # #REVISION HISTORY: # 06/19/05 Version 1.41 Fixed variable warnings when values not supplied. # 02/14/03 Version 1.4 Updated to work PHP 4.1.2 or later only. # 05/21/02 Version 1.32 Resolved an issue in the "to" field causing some people to # receive multiple emails with each mailing. Optimized code a bit more. # 04/25/02 Version 1.3 - no modifications # 02/18/02 Version 1.21- Changed the attachment lable so it prints actual file name # 02/01/02 Version 1.2 - Minor modifications # 09/28/01 Version 1.1 # 08/01/01 Original Version # #CONTACT INFORMATION: # http://www.davelozinski.com/cgi-bin/email_lozinski.pl # #Begin the customizable configurations: #The title of the web page and the text on the "submit" button $TITLE = "Send Me Email!"; #The background color of the web page, the normal text color, and the #text color for the information that is required. Note that these can #either be in hexidecimal format, or words as the settings below show. #If you specify the color code in hex, it expects a leading '#' #pound sign. $BGCOLOR = "#000000"; $TEXT_COLOR_NORMAL = "#0088FF"; $REQUIRED_TEXT_COLOR = "yellow"; #The URL to a background picture for the web pages. $BACKGROUND_URL = ""; #The URL to the executable directory where this script is located. #DO NOT put a trailing slash '/' character! $CGI_DIR = "."; #Set to "1" if you want the optional fields shown in the email form. #Set to "0" (zero) otherwise. $SHOW_OPTIONAL_FIELDS = 1; #The email address where you want all the email from this page sent to if #no destination email is supplied by the "to" parameter. $DESTINATION_EMAIL = "destination@your_domain.com"; #The email address that will be placed in the "from" field of all emails sent back to #the end user. $FROM_EMAIL = "from_email@yourdomain.com"; #Set to "1" if you want the optional file upload field shown in the email form. #Set to "0" (zero) otherwise. #BE CAREFUL WHEN USING THIS FEATURE AS PEOPLE COULD POTENTIALLY EMAIL YOU #VIRUSES! Of course, this is true of any email you receive, but allowing #email attachments from strangers greatly increases this risk. # $SHOW_ATTACHMENT_FIELD = 1; ##################################################################### ######## NOTHING FROM HERE DOWN SHOULD NEED TO BE CONFIGURED ######## ##################################################################### #These are set up here in case the PHP developers decide to screw #everyone over again by changing variable names, introducing new #variables, completely changing PHP configuration files, or doing #something else for future releases. ######### if (array_key_exists ("mail", $_REQUEST)) { $mail = $_REQUEST["mail"]; } else { $mail = ""; } if (array_key_exists ("subject", $_REQUEST)) { $subject = $_REQUEST["subject"]; } else { $subject = ""; } if (array_key_exists ("message", $_REQUEST)) { $message = $_REQUEST["message"]; } else { $message = ""; } if (array_key_exists ("users_name", $_REQUEST)) { $users_name = $_REQUEST["users_name"]; } else { $users_name = ""; } if (array_key_exists ("users_email", $_REQUEST)) { $users_email = $_REQUEST["users_email"]; } else { $users_email = ""; } if (array_key_exists ("users_country", $_REQUEST)) { $users_country = $_REQUEST["users_country"]; } else { $users_country = ""; } if (array_key_exists ("state_address", $_REQUEST)) { $state_address = $_REQUEST["state_address"]; } else { $state_address = ""; } if (array_key_exists ("attach_name", $_REQUEST)) { $attach_name = $_REQUEST["attach_name"]; } else { $attach_name = ""; } if (array_key_exists ("keep_copy", $_REQUEST)) { $keep_copy = $_REQUEST["keep_copy"]; } else { $keep_copy = ""; } if (array_key_exists ("attach", $_FILES)) { $attach_name = $_FILES["attach"]["name"]; $attach_type = $_FILES["attach"]["type"]; $attach_size = $_FILES["attach"]["size"]; $temp_file_name = $_FILES["attach"]["tmp_name"]; } ######## Main body of code ######## StartHTML(); if (!$mail) { PrintForm(); } else { if (!(check_form_data())) { if (send_mail()) { reply_to_user(); } else { echo ("Your email was not sent.
\n"); } } } FinishHTML(); ######## php functions ######## ######################## #function StartHTML #This function prints the start of the feedback form web page. ######################## function StartHTML() { global $BGCOLOR, $BACKGROUND_URL, $TITLE, $TEXT_COLOR_NORMAL; ?> <?=$TITLE?>

Your name:
* Your email:
Have a copy of your message sent to you?

Your country:
Your State/Province:

* Subject of the message:

* Your message:

Attachment:
\n"); } ?>

* - indicates a required field.

\n"); $error = 1; } if (!preg_match("/[a-zA-Z]/", $subject) ) { echo ("Your message cannot be sent without a subject.

\n"); $error = 1; } if (!preg_match("/[a-zA-Z]/", $message) ) { echo ("You seemed to have forgotten to enter the email message you wish to send.

\n"); $error = 1; } else { $message = stripslashes($message); } if ( (preg_match("/[\[\;\>\<\&\*\^\$\(\)\`\|\]\']/", $subject)) || (preg_match("/[\[\;\>\<\&\*\^\$\(\)\`\|\]\']/", $users_email)) ) { echo ("For security reasons, you cannot have any of the following characters in your email or subject fields: [ ; < > & * ` | ]

\n"); $error = 1; } return $error; } #check_form_data ######################## ######################## #This function returns a web page to the user confirming their email ######################## function reply_to_user() { global $users_name, $users_email, $users_country, $state_address, $message, $SHOW_ATTACHMENT_FIELD, $attach_name; echo ("Thank you for sending me email!

\n"); echo ("Below is a copy of the information you sent me:
\n"); echo ("
\n"); if ($users_name != "") { echo ("
Your name:\n
$users_name

\n"); } echo ("
Your email:\n
$users_email

\n"); if ($users_country != "") { echo ("
Your country:\n
$users_country

\n"); } if ($state_address != "") { echo ("
Your state:\n
$state_address

\n"); } echo ("
Your message:\n
$message

\n"); if ($SHOW_ATTACHMENT_FIELD) { if ($attach_name != "") { echo ("
File attachment:\n
$attach_name

\n"); } } echo ("
\n"); } #reply_to_user ######################## ######################## #This function does the work of sending the emails ######################## function send_mail() { global $SHOW_ATTACHMENT_FIELD, $DESTINATION_EMAIL, $FROM_EMAIL, $users_email, $subject, $users_name, $users_country, $state_address, $message, $keep_copy, $TITLE, $attach_name, $attach_type, $attach_size, $temp_file_name; $msg_body = ""; $error = 0; #No error. If email could not be sent, will set to 1. $mailheaders = "From: $users_email\n"; $mailheaders .= "X-Mailer: Lozinski's PHP Email Script\n"; if ($users_name != "") { $msg_body .= "$users_name - "; } $msg_body .= "$users_email filled out the email form on your website.\n"; if ($users_country != "") { $msg_body .= "They are in the country of: $users_country\n"; } if ($state_address != "") { $msg_body .= "They are writing from the state of: $state_address\n\n"; } $msg_body .= "The following is what they had to say:\n\n"; $msg_body .= "$message\n"; if ($attach_size > 0) { #If there were attachments if ($SHOW_ATTACHMENT_FIELD) { $file = fopen($temp_file_name, "r"); $contents = fread($file, $attach_size); $encoded_attach = chunk_split(base64_encode($contents)); fclose($file); } $mailheaders .= "MIME-version: 1.0\n"; $mailheaders .= "Content-type: multipart/mixed; "; $mailheaders .= "boundary=\"Message-Boundary\"\n"; $mailheaders .= "Content-transfer-encoding: 7BIT\n"; $body_top = "--Message-Boundary\n"; $body_top .= "Content-type: text/plain; charset=US-ASCII\n"; $body_top .= "Content-transfer-encoding: 7BIT\n"; $body_top .= "Content-description: Mail message body\n\n"; $msg_body = $body_top . $msg_body; if ($SHOW_ATTACHMENT_FIELD) { if ($attach_name != "") { $msg_body .= "\n\n--Message-Boundary\n"; $msg_body .= "Content-type: $attach_type; name=\"$attach_name\"\n"; $msg_body .= "Content-Transfer-Encoding: BASE64\n"; $msg_body .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n"; $msg_body .= "$encoded_attach\n"; } } $msg_body .= "--Message-Boundary--\n"; } #If there were attachments if (mail(stripslashes($DESTINATION_EMAIL), $subject, $msg_body, $mailheaders)) { $error = 0; } else { $error = 1; } if ($keep_copy) { $mailheaders = "From: $FROM_EMAIL\n"; $msg_body = "The following is what you wrote from the "; $msg_body .= "\"$TITLE\" webpage...:\n\n"; $msg_body .= $message . "\n"; if (mail(stripslashes($users_email), $subject, $msg_body, $mailheaders)) { $error = 0; } else { $error = 1; } } return !($error); } #send_mail ######################## ?>