Location: PHPKode > projects > Spacemarc News > spacemarc-news/admin/invia_email_utenti.php
<?php

/*****************************************************************
*  Spacemarc News
*  Version: 1.2.0
*  Author and copyright (C): Marcello Vitagliano
*  Web site: http://www.spacemarc.it
*  License: GNU General Public License
*
*  This program is free software: you can redistribute it and/or
*  modify it under the terms of the GNU General Public License
*  as published by the Free Software Foundation, either version 3
*  of the License, or (at your option) any later version.
*
*  Current file: invia_email_utenti.php
*****************************************************************/
session_start();
define('IN_NEWS', true);
header('Content-type: text/html; charset=ISO-8859-1');

//includo i file di configurazione
require_once (dirname(__FILE__) . '/../config.php');
require_once (dirname(__FILE__) . '/functions.php');
require_once (dirname(__FILE__) . '/../lang/lang.php');
$db = mysql_connect($db_host, $db_user, $db_password) or die("Impossibile connettersi a MySQL<br />Numero errore: " . mysql_errno() . "<br />Tipo di errore: " . mysql_error());
mysql_select_db($db_name, $db) or die("Impossibile selezionare il database $db_name<br />Numero errore: " . mysql_errno() . "<br />Tipo di errore: " . mysql_error());
check_login();

// se NON sono un amministratore e voglio visualizzare questa pagina, redirigo all'elenco news personale

if ($_SESSION['livello_id'] != 1) {
    header("Location: " . $dir_admin . "/elenco_news.php");
    exit();
}
$err_email = NULL;
$mail_msg = NULL;
$get_user_id = (isset($_GET['user_id'])) ? $_GET['user_id'] : NULL;

if (isset($_POST['submit'])) {

    //controllo campi
    
    if (trim($_POST['oggetto']) == "" || trim($_POST['messaggio']) == "" || empty($_POST['email'])) {
        $err_email = "<div id=\"error\">" . $lang['email_utenti_campi'] . "</div>";
    }
    else {

        //controllo se ho scelto di ricevere una copia dell'email
        
        if (isset($_POST['cb_admin'])) {
            $result = mysql_query("SELECT email FROM $tab_utenti WHERE user_id=" . intval($_SESSION['user_id']) . " LIMIT 1");
            $row = mysql_fetch_array($result);
            $mail_admin = "," . $row['email'];
        }
        else {
            $mail_admin = NULL;
        }
        $to = $_SERVER['SERVER_ADMIN'];
        $oggetto = stripslashes(trim($_POST['oggetto']));
        $messaggio = stripslashes($_POST['messaggio']) . "\n\n--\nMessaggio inviato in CCN da un Amministratore delle News su http://" . $_SERVER['HTTP_HOST'];
        $to_bbc = implode(",", $_POST['email']);
        $header = "From: " . $_SERVER['SERVER_ADMIN'] . "\n";
        $header.= "Bcc: " . $to_bbc . $mail_admin . "\n";
        $header.= "Reply-To: " . $_SERVER['SERVER_ADMIN'] . "\n";
        $header.= "Return-Path: " . $_SERVER['SERVER_ADMIN'] . "\n";
        $header.= "X-Mailer: PHP/" . phpversion() . "\n";
        $header.= "MIME-Version: 1.0\n";
        $header.= "Content-type: text/plain; charset=ISO-8859-1\n";
        $header.= "Content-Transfer-encoding: 7bit\n";
        
        if (@mail($to, $oggetto, $messaggio, $header)) {
            $mail_msg = "<div id=\"success\">" . $lang['email_utenti_ok'] . "</div> <script language=\"JavaScript\" type=\"text/JavaScript\">setTimeout('window.close()', 2500)</script>";
        }
        else {
            $mail_msg = "<div id=\"error\">" . $lang['email_utenti_error'] . "</div>";
        }
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
  <head>    
    <title>Invia email agli utenti
    </title>    
    <link rel="stylesheet" href="../style.css" type="text/css" />		
<script language="JavaScript" src="../javascript.js" type="text/JavaScript"></script>  
  </head>  
  <body>    
    <div align="center">
<?php echo $err_email;
echo $mail_msg; ?><br />      
      <span class="text"><b>
          <?php echo $lang['email_utenti_descr']; ?></b>
      </span><br />      
      <form method="post" name="sendmail" action="invia_email_utenti.php?user_id=<?php echo htmlspecialchars($get_user_id, ENT_QUOTES); ?>">        
        <table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">          
          <tr>               
            <td align="right" class="text" width="23%" bgcolor="#EEEEEE">Oggetto</td>            
            <td align="left" bgcolor="#EEEEEE">              
              <input type="text" name="oggetto" size="30" maxlength="50" /></td>          
          </tr>          
          <tr>               
            <td align="right" class="text" valign="top" bgcolor="#EEEEEE">Destinatari</td>            
            <td align="left" bgcolor="#EEEEEE" class="text2">              
              <select name="email[]" multiple="multiple" id="email" size="8" style="width: 200px">
<?php

//estraggo le email degli utenti selezionati via GET
$ids = explode(",", $get_user_id);

foreach($ids as $k => $v) {
    
    if (!preg_match('/^[0-9]{1,4}$/', $v)) {
        unset($ids[$k]);
    }
}
$ids2 = implode(",", $ids);
$sel_utenti = mysql_query("SELECT email FROM $tab_utenti WHERE user_id IN ($ids2) ORDER BY email ASC");

while ($riga = @mysql_fetch_array($sel_utenti)) {
    echo "<option value=\"" . $riga['email'] . "\" selected=\"selected\">" . $riga['email'] . "</option>\n";
}
?>              
              </select><br />Seleziona:                
              <a href="javascript:void(0)" onclick="listbox_selectall('email', true)" class="piccolo">tutti</a>,                
              <a href="javascript:void(0)" onclick="listbox_selectall('email', false)" class="piccolo">nessuno</a></td>          
          </tr>          
          <tr>               
            <td align="right" class="text" valign="top" bgcolor="#EEEEEE">Messaggio</td>            
            <td align="left" bgcolor="#EEEEEE">
<textarea name="messaggio" cols="31" rows="7"></textarea></td>          
          </tr>          
          <tr>               
            <td align="right" bgcolor="#EEEEEE"></td>            
            <td align="left" bgcolor="#EEEEEE" class="text2">              
              <input type="checkbox" name="cb_admin" id="cb_admin" checked="checked" />              
              <label for="cb_admin">Invia una copia anche al mio indirizzo
              </label><br /><br /></td>          
          </tr>          
          <tr>            
            <td align="center" bgcolor="#EEEEEE" colspan="2">              
              <input type="submit" name="submit" value="Invia email" /></td>          
          </tr>        
        </table>      
      </form>    
    </div>  
  </body>
</html>
Return current item: Spacemarc News