Location: PHPKode > projects > WebAddressBook > webaddressbook/extensions/mailing_lists/index.php
<?

if(isset($_SESSION['username'])) {
    if(file_exists($ext_path.'languages/'.$_SESSION['language'].'.lang.php')) {
        include($ext_path.'languages/'.$_SESSION['language'].'.lang.php');
    } else {
         include($ext_path.'languages/English.lang.php');
    }
    include($ext_path.'installed.inc.php');

    $ext_name = $lang['ext_name'];

    // an extension has been chosen
    if(isset($_REQUEST['ext']) && $_REQUEST['ext'] == 'mailing_lists') {
        $smarty->assign("ext_name", $ext_name);

        // the user wants to send mail
        if( isset($_REQUEST['submit']) ) {
            if(isset($_POST['mailsubmit'])) { // send mail by php mail()
                $user_array = db_get_user($_SESSION['uid']);
                
                $header  = "From: ".$_REQUEST['sender']."<".$_REQUEST['email'].">\n";
                $header .= "X-Sender-IP: ".$_SERVER["REMOTE_ADDR"]."\n";
                $visibility = $_REQUEST['visibility'] == "cc" ? "Cc" : "Bcc";
                                
                foreach($_REQUEST['receiver'] as $elem) {
                    $header .= $visibility . ": " . $elem . "\r\n";
                }
                $header .= "Content-Type: text/plain";

                $subject = $_REQUEST['subject'];
                $message = $_REQUEST['message'];
                $receiver = $_REQUEST['email']; // standard receiver is the user self, all others are in the header in cc/bcc

                // store sender and email for further use
                $ret1 = db_change_useroption($_SESSION['uid'], "sender", $_REQUEST['sender']);
                $ret2 = db_change_useroption($_SESSION['uid'], "email", $_REQUEST['email']);
                
                $ok = mail($receiver,$subject,$message,$header);
                if($ok) {
                    $smarty->assign("result", $lang['successfully_sent']);
                } else {
                    $smarty->assign("result", $lang['error_while_sending']);
                }
                
                $smarty->display('mailing_lists_result.tpl');
            } else { // show message creation form
                //translations
                $smarty->assign("lang_sender", $lang['sender']);
                $smarty->assign("lang_mail1", $lang['mail1']);
                $smarty->assign("lang_subject", $lang['subject']);
                $smarty->assign("lang_message", $lang['message']);
                $smarty->assign("lang_submit", $lang['submit']);
                $smarty->assign("lang_reset", $lang['reset']);
                // vars
                $person_array = db_get_persons($_SESSION['uid'], $_REQUEST['group']);
                $smarty->assign("person_array", $person_array);
                $row = db_get_user($_SESSION['uid']);
                $smarty->assign("sender", $row['SENDER']);
                $smarty->assign("email", $row['EMAIL']);
                
                $smarty->display('mailing_lists_form.tpl');
            }
        } else { // no submit, show the input mask
            // translations
            $smarty->assign("lang_group",$lang['group']);
            $smarty->assign("lang_visibility",$lang['visibility']);
            $smarty->assign("lang_cc",$lang['cc']);
            $smarty->assign("lang_bcc",$lang['bcc']);
            $smarty->assign("lang_ok",$lang['ok']);
            // vars
            $group_array = db_get_groups($_SESSION['uid']);
            $smarty->assign("groups", $group_array);
            
            $smarty->display('mailing_lists_index.tpl');
        }
    }
} else {
    include('unauthorized.inc.php');
}
?>
Return current item: WebAddressBook