}
 $template->assign("fields", $fields);
 $template->assign("captions", $captions);
 $template->assign("is_email", 1);
 $emailHtml = $template->render();
 if (count($emaillist)) {
     //This is an easy way to remove duplicates
     $emaillist = array_flip(array_flip($emaillist));
     if (count($emaillist)) {
         //This is an easy way to remove duplicates
         $emaillist = array_flip(array_flip($emaillist));
         if (!defined("SYS_SMTP")) {
             include_once BASE . "subsystems/smtp.php";
         }
         $headers = array("MIME-Version" => "1.0", "Content-type" => "text/html; charset=iso-8859-1");
         if (exponent_smtp_mail($emaillist, "", $f->subject, $emailHtml, $headers) == false) {
             $i18n = exponent_lang_loadFile('modules/formbuilder/actions/submit_form.php');
             echo $i18n['err_smtp'];
         }
     }
 }
 //If is a new post show response, otherwise redirect to the flow.
 if (!isset($_POST['data_id'])) {
     $template = new template("formbuilder", "_view_response");
     global $SYS_FLOW_REDIRECTIONPATH;
     $SYS_FLOW_REDIRECTIONPATH = "editfallback";
     $template->assign("backlink", exponent_flow_get());
     $SYS_FLOW_REDIRECTIONPATH = "exponent_default";
     $template->assign("response_html", $f->response);
     $template->output();
 } else {
    }
}
$headers = array();
$headers['From'] = $config->from_name . ' <' . $config->from_address . '>';
if ($config->replyto_address != '') {
    $headers['Reply-to'] = $config->replyto_address;
}
if (!defined('SYS_USERS')) {
    include_once BASE . 'subsystems/users.php';
}
$emails = array();
foreach ($db->selectObjects('contact_contact', "location_data='" . serialize($loc) . "'") as $c) {
    if ($c->user_id != 0) {
        $u = exponent_users_getUserById($c->user_id);
        $emails[] = $u->email;
    } else {
        if ($c->email != '') {
            $emails[] = $c->email;
        }
    }
}
if (!defined('SYS_SMTP')) {
    include_once BASE . 'subsystems/smtp.php';
}
if (exponent_smtp_mail($emails, $config->from_address, $config->subject, $msg, $headers)) {
    $template = new template('contactmodule', '_final_message');
    $template->assign('message', $config->final_message);
    $template->output();
} else {
    echo $i18n['smtp_error'];
}
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################
if (!defined('EXPONENT')) {
    exit('');
}
if (!defined('SYS_SMTP')) {
    require_once BASE . 'subsystems/smtp.php';
}
//filter the message thru the form template for formatting
$msgtemplate = new formtemplate('email', '_' . $_POST['formname']);
$msgtemplate->assign('post', $_POST);
$msg = $msgtemplate->render();
$ret = false;
//make sure we this is from a valid event and that the email addresses are listed, then mail
if (isset($_POST['id'])) {
    $event = $db->selectObject('calendar', 'id=' . intval($_POST['id']));
    $email_addrs = array();
    if ($event->feedback_email != '') {
        $email_addrs = split(',', $event->feedback_email);
        $email_addrs = array_map('trim', $email_addrs);
        $ret = exponent_smtp_mail($email_addrs, 'website@' . HOSTNAME, $_POST['subject'], $msg);
    }
}
$template = new template('calendarmodule', '_feedback_submitted');
$template->assign('success', $ret ? 1 : 0);
$template->output();
} else {
    $newpass = '';
    for ($i = 0; $i < rand(12, 20); $i++) {
        $num = rand(48, 122);
        if ($num > 97 && $num < 122 || $num > 65 && $num < 90 || $num > 48 && $num < 57) {
            $newpass .= chr($num);
        } else {
            $i--;
        }
    }
    // Send message
    if (!defined('SYS_SMTP')) {
        require_once BASE . 'subsystems/smtp.php';
    }
    $e_template = new template('loginmodule', '_email_resetdone', $loc);
    $e_template->assign('newpass', $newpass);
    $msg = $e_template->render();
    if (!defined('SYS_USERS')) {
        require_once BASE . 'subsystems/users.php';
    }
    $u = exponent_users_getUserById($tok->uid);
    if (!exponent_smtp_mail($u->email, $i18n['from_name'] . ' <' . $i18n['from_email'] . '@' . HOSTNAME . '>', $i18n['title'], $msg)) {
        echo $i18n['smtp_error'];
    } else {
        // Save new password
        $u->password = md5($newpass);
        exponent_users_saveUser($u);
        $db->delete('passreset_token', 'uid=' . $tok->uid);
        echo $i18n['sent'];
    }
}
                    $ban = $db->selectObject('inbox_contactbanned', 'user_id=' . $id . ' AND owner=' . $user->id);
                }
                if ($ban) {
                    $failed->body = sprintf($i18n['failed_403'], $message->body);
                    $db->insertObject($failed, 'privatemessage');
                } else {
                    $message->recipient = $id;
                    $inbox_userconfig = $db->selectObject('inbox_userconfig', 'id=' . $id);
                    if (!$inbox_userconfig) {
                        $inbox_userconfig->forward = 1;
                    }
                    if ($inbox_userconfig->forward == 1 && $u->email != '') {
                        // Forward the message to their email account
                        $emails[] = $u->email;
                    }
                    $db->insertObject($message, 'privatemessage');
                }
            }
        }
    }
    if (count($emails)) {
        $body = $message->body;
        $headers = array('MIME-Version' => '1.0', 'Content-type' => 'text/html; charset=iso-8859-1', 'Reply-to' => $reply_to, 'From' => $reply_to);
        if (exponent_smtp_mail($emails, '', $message->subject, '<html><body>' . $message->body . '</body></html>', $headers) == false) {
            echo $i18n['err_smtp'];
        }
    }
    exponent_flow_redirect();
} else {
    echo SITE_403_HTML;
}