Codice PHP:
/***************************************
** Override checking, recipient, templates,
** subject etc.
***************************************/
if(isset($postvars['thankyou_page']) AND $postvars['thankyou_page'] != '') $thankyou_page = $postvars['thankyou_page'];
if(isset($postvars['recipient']) AND $postvars['recipient'] != ''){
$recipient = $postvars['recipient'];
}elseif(!isset($recipient) OR $recipient == ''){
echo 'Form incorrectly configured - no recipient defined. Please see the readme for details.';
exit;
}
if(isset($postvars['subject']) AND $postvars['subject'] != '') $subject = $postvars['subject']; elseif(!isset($subject) OR $subject == '') $subject = 'portofinodive Form Processor.('.$HTTP_REFERER.')';
if((isset($postvars['use_templates']) AND ($use_templates = $postvars['use_templates']) == 1) OR (isset($use_templates) AND $use_templates == 1)){
if(isset($postvars['tpl_thankyou']) AND $postvars['tpl_thankyou'] != '') $tpl_thankyou = $postvars['tpl_thankyou'];
if(isset($postvars['tpl_email']) AND $postvars['tpl_email'] != '') $tpl_email = $postvars['tpl_email'];
}
/***************************************
** Check to see if email was included in
** form. If so check validity (if required).
** If this fails, the redirect is after
** the config file is read in. To enable
** invalid email urls in the conf file.
***************************************/
$regex = '^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3}))$';
if(isset($postvars['email']) AND $postvars['email'] != ''){
$email = $postvars['email'];
if(isset($check_email) AND $check_email == 1 AND !eregi($regex, $email)){
$email_redirect = 1;
}
}elseif(isset($postvars['email_required']) AND $postvars['email_required'] != ''){
$email = $postvars['email_required'];
if(isset($check_email) AND $check_email == 1 AND !eregi($regex, $email)){
$email_redirect = 1;
}
}
/***************************************
** Parse the configuration file if one
** was specified.
***************************************/
if(isset($postvars['configfile']) AND $postvars['configfile'] != '' AND file_exists($postvars['configfile'])){
$file_array = file($postvars['configfile']);
for($i=0; $i<count($file_array); $i++){
$var_name = trim(substr(trim($file_array[$i]),0,strpos($file_array[$i], '=')));
$var_value = trim(substr(trim($file_array[$i]),strpos($file_array[$i], '=')+1));
$$var_name = $var_value;
}
}
/***************************************
** The email redirect from above
***************************************/
if(isset($email_redirect) AND $email_redirect == 1){
header('Location: '.$invalid_email);
exit;
}
/***************************************
** Setup the objects.
***************************************/
$mail = new html_mime_mail();
if($use_templates == 1){
$tpl = new template;
if($tpl_thankyou != '') $tpl->load_file('main', $tpl_thankyou);
if($tpl_email != '') $tpl->load_file('email', $tpl_email);
}
/***************************************
** Begin the main loop. First set the
** arrays that hold the values to email.
***************************************/
$message = array();
$message_values = array();
$num_attachments = 0;
while(list($key,$value) = each($postvars)){
check_required($key, $value);
if((int)phpversion() < 4) if(file_upload_php3($key,$value) == TRUE) continue;
main($key, $value, $message, $message_values);
}
if((int)phpversion() >= 4 AND isset($HTTP_POST_FILES) AND is_array($HTTP_POST_FILES)) file_upload_php4($HTTP_POST_FILES);
/***************************************
** Post processing stuff.
***************************************/
padding($message, '.');
for($i=0; $i<count($message); $i++) $message[$i] .= '..:'.$message_values[$i];
$time = date('H:i', time());
$date = date('l m F Y', time());
/***************************************
** Constructs the email. If there are
** attachments it uses the mime mail
** class, if not then normal mail().
***************************************/
if(isset($use_templates) AND $use_templates == 1 AND $tpl_email != ''){
$tpl->register('email','REMOTE_ADDR,REMOTE_HOST,HTTP_REFERER,HTTP_USER_AGENT,recipient,num_attachments,subject,time,date');
$tpl->parse('email');
$body = $tpl->return_file('email');
while(preg_match('/({.+})/U',$body, $matches) == TRUE){
$body = str_replace($matches[1], '', $body);
}
}else{
$body = 'At '.$time.' on '.$date.', le info che hai inserito ti arriveranno tramite mail'.getenv('HTTP_REFERER')." :\r\n\r\n";
$body .= implode("\r\n", $message)."\r\n\r\n";
$body .= (isset($postvars['addhostip']) AND $postvars['addhostip'] == 1) ? 'Remote IP: '.getenv('REMOTE_ADDR')."\r\nRemote hostname: ".getenv('REMOTE_HOST')."\r\n" : '';
}
if($num_attachments > 0){
$mail->add_body_text($body);
$mail->build_message();
$mail->send('', $recipient, '', $email, $subject);
}else{
$headers = 'Content-Type: '.$email."\r\n";
$headers = 'From: '.$email."\r\n";
mail($recipient, $subject, $body, $headers);
}
/***************************************
** Email sent, now either finish the template
** and output it, redirect to the thank you
** page or simply call the thank_you()
** function.
***************************************/
if(isset($use_templates) AND $use_templates == 1 AND $tpl_thankyou != ''){
$tpl->register('main','REMOTE_ADDR,REMOTE_HOST,HTTP_REFERER,HTTP_USER_AGENT,recipient,num_attachments,subject,time,date');
$tpl->parse('main');
$output = $tpl->return_file('main');
while(preg_match('/({.+})/U',$output, $matches) == TRUE){
$output = str_replace($matches[1], '', $output);
}
echo $output;
}elseif(isset($thankyou_page) AND $thankyou_page != ''){
header('Location: '.$thankyou_page);
exit;
}
?>