Subversion-Projekte lars-tiefland.content-management

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

<?
        $self=basename($PHP_SELF);
        $DB="verteiler";
        define ("modul_name", "mail_verteiler");
        define ("tool_name", "versenden");
        require_once "../Online-Shop/connect2.php";
        
        if (!isset($user_rechte[mail_verteiler][versenden][html]))
        {
                header("Location: mailVerteilerSelect.php");
        }

        if ($action)
        {
        
                $query="SELECT * FROM Verteiler where ID = $Verteiler_NR";
                $result_Verteiler = mysql_query ($query) or die (mysql_errno().": ".mysql_error()."<hr>$query<hr>");
                $Verteiler=mysql_fetch_array($result_Verteiler);

                $headers["From"]="From: $Verteiler[Absender]";
                //$headers["CC"]="";
                //$headers["BCC"]="";

                unset($text);
                $action="MIXED";
                switch ($action)
                {
                        case "ATTACHMENTS":
                                srand ((double)microtime()*1000000);
                                $splitter = rand();
      
                                $headers["Mime_header0"]="Mime-Version: 1.0";
                                $headers["Mime_header1"]="Content-Type: multipart/mixed;";
                                $headers["Mime_header2"]="\tboundary=\"----SPLITTER_".$splitter."_0\"";
                                $headers["Mime_header3"]="This is a multi-part message in MIME format.";
                                $headers=implode("\n",$headers);

                                if ($attach)
                                {
                                        foreach (array_keys($attach) as $elem)
                                        {
                                                if ($attach[$elem] != "none")
                                                {
                                                        $filename = $attach[$elem];
                                                        $fd = fopen ($filename, "r");
                                                        $contents = fread ($fd, filesize ($filename));
                                                        fclose ($fd);

                                                        $daten = chunk_split (base64_encode($contents));
          
                                                        $attach_text = array(
                                                                "------SPLITTER_".$splitter."_0",
                                                                "Content-Type: ".$attach_type[$elem].";",
                                                                "\tname=\"".$attach_name[$elem]."\"",
                                                                "Content-Transfer-Encoding: base64",
                                                                "Content-Disposition: attachment;",
                                                                "\tfilename=\"".$attach_name[$elem]."\"",
                                                                "\n",
                                                                $daten,
                                                                "\n"
                                                                );
                                                        $attach_text = implode("\n",$attach_text);
                                                        $attachments = $attachments.$attach_text;
                                                }
                                        }
                                }

                                $text = array(
                                        "------SPLITTER_".$splitter."_0",
                                        "Content-Type: multipart/alternative;",
                                        "\tboundary=\"----SPLITTER_".$splitter."_1\"\n\n",
                                        "------SPLITTER_".$splitter."_1",
                                        "Content-Type: text/plain;",
                                        "\tcharset=\"iso-8859-1\"",
                                        "Content-Transfer-Encoding: quoted-printable\n",
                                        $Verteiler[Begruessung],
                                        $message[PLAIN],
                                        $Verteiler[Schlusstext],
                                        "\n\n------SPLITTER_".$splitter."_1--",
                                        $attachments,
                                        "\n\n------SPLITTER_".$splitter."_0--"
                                        );
                                $text = implode("\n",$text);
                        break;

                        case "MIXED":
                                /* INIT $boundary */
                                srand ((double)microtime()*1000000);
                                $boundary="";
                                for ($a=0; $a <= 15; $a++)
                                {
                                        $boundary=$boundary.sprintf("%02X",rand(0,255));
                                }
                                $boundary="=_".$boundary;

                                $headers["MIME-Version"]        =       "MIME-Version: 1.0";
                                $headers["Content-Type"]        =       "Content-Type: multipart/alternative;";
                                $headers["boundary"]            =       chr(9)."boundary=\"".$boundary."\"";

                                $CONTENT_HEADERS=array
                                (
                                        "PLAIN" => array(
                                        "--".$boundary,
                                        "Content-Type: text/plain; charset=\"ISO-8859-1\"",
                                        "Content-Transfer-Encoding: 7bit",
                                        "",""
                                        ),
                                        "HTML" => array(
                                        "",
                                        "--".$boundary,
                                        "Content-Type: text/html; charset=\"ISO-8859-1\"",
                                        "Content-Transfer-Encoding: quoted-printable",
                                        "",""
                                        )
                                );

                                $message[HTML]=stripslashes(preg_replace ("/=/", "=3D", $message[HTML]."<br><br><a href=\"[logout_link]\">Newsletter abbestellen</a>"));
                                $message[PLAIN]=$message[PLAIN]."\n\n[logout_link]";
                                        
                                foreach(array_keys($CONTENT_HEADERS) as $elem)
                                {
                                        $message[$elem]=join($CONTENT_HEADERS[$elem],"\n").$message[$elem];
                                }
                                $text=join($message,"\n")."\n--".$boundary."--\n";
                        break;

                        default:
                                $text = array(
                                        $Verteiler[Begruessung],
                                        $message[PLAIN],
                                        $Verteiler[Schlusstext],
                                        "\n\n[logout_link]",
                                        );
                                $text = implode("\n",$text);
                        break;
                } // end of switch
                        
                // Mailadressen filtern und formatieren
                preg_match_all("/[A-Za-z0-9-_.+]+\@[A-Za-z0-9-_.+]+\.[A-Za-z]+/", $To, $matches);
                $matches=$matches[0];

                foreach($matches as $mailadresse)
                {
                        $logout_link = $web_rechte[mail_verteiler][verteiler][logout_link]."?m=".$mailadresse."&v=".$Verteiler[ID];

                        $text2=preg_replace
                        (
                                "/\[logout_link\]/",
                                stripslashes
                                (
                                        preg_replace
                                        (
                                                "/=/",
                                                "=3D",
                                                $logout_link
                                        )
                                ),
                                $text
                        );
                        // Mails verschicken wird überbewertet!
                        //mail($mailadresse, $Verteiler[Betreff], $text2, implode("\n",$headers));
                        // In den Mailspool packen
                        
                                $mail[webs_ID] = $webs[ID];
                                $mail[to] = $mailadresse;
                                $mail[cc] = '';
                                $mail[bcc] = '';
                                $mail[subject] = $Verteiler[Betreff];
                                $mail[from] = $Verteiler[Absender];
                                $mail[header_add] = implode("\n",$headers);
                                $mail[text] = $text2;
                                $mail[takeoff] = date("Y-m-d H:i:s"); // Takeoff ist immer NOW (Format: "2005-10-20 13:17:23"
                                $mail[erstellt_von] = $PHP_AUTH_USER;

                                $query_spool = "USE content_management";
                                $result = mysql_query ($query_spool, $localhost_dbh) or die (mysql_errno().": ".mysql_error()."<hr>$query_spool<hr>");

                                $query_spool = "
                                        INSERT INTO 
                                                `mailspool_out` 
                                        ( 
                                                `ID` , 
                                                `webs_ID` , 
                                                `to` , 
                                                `cc` , 
                                                `bcc` , 
                                                `subject` , 
                                                `from` , 
                                                `header_add` , 
                                                `text` , 
                                                `takeoff` , 
                                                `erstellt_am` , 
                                                `erstellt_von` 
                                        ) 
                                        VALUES 
                                        (
                                                '', 
                                                '$mail[webs_ID]', 
                                                '$mail[to]', 
                                                '$mail[cc]' , 
                                                '$mail[bcc]' , 
                                                '$mail[subject]', 
                                                '$mail[from]', 
                                                '$mail[header_add]', 
                                                '$mail[text]', 
                                                '$mail[takeoff]', 
                                                NOW(), 
                                                '$mail[erstellt_von]'
                                        );
                                ";
                                $result = mysql_query ($query_spool, $localhost_dbh) or die (mysql_errno().": ".mysql_error()."<hr>$query_spool<hr>");
                        
                        
                        
                }
                header("Location: mailsent.php?count=".count($matches));
        } // end of if ($action)

        $Verteiler=array();
        $result = mysql_query ("SELECT * FROM Verteiler order by name") or die (mysql_errno().": ".mysql_error());
        while($zeile=mysql_fetch_array($result))
        {
                $Verteiler[$zeile[ID]]=$zeile;
        }
        
        if (!$Verteiler_NR)
        {
                $Verteiler_NR = array_keys($Verteiler);
                $Verteiler_NR = $Verteiler_NR[0];
        }
?>
<html>
<head>
<title>Mail versenden</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="author" content="Webagentur Niewerth - www.weban.de">
<meta name="revisit-after" content="30 days">
<meta name="language" content="deutsch, de">
<meta name="distribution" content="global">
<meta name="robots" content="all">
<link rel=stylesheet type="text/css" href="../buttons.css">
<style type="text/css">
<!--
a {  color: #<? echo $webs[font_color_rechts] ?>}
-->
</style>
<script type="text/javascript">
   _editor_url = "../htmlarea/";
   _editor_lang = "de";
</script>
<script type="text/javascript" src="../htmlarea/htmlarea.js"></script>
</head>

<body bgcolor="#<? echo $webs[bgcolor_seite] ?>" leftmargin="20" topmargin="10" marginwidth="20" marginheight="10" text="#<? echo $webs[font_color_rechts] ?>">
<font color="#FF0000" size="+1">Modul NICHT benutzen! "Bauarbeiten"!</font>
<form method="post" action="#" enctype="multipart/form-data">
  <table width="600" border="1" cellspacing="0" cellpadding="3" bordercolorlight="#FFFFFF" bordercolordark="#999999">
    <tr> 
      <td bgcolor="#<? echo $webs[bgcolor_links] ?>" class="headline" colspan="2">Verteiler 
        senden: <input type="hidden" name="Verteiler_NR" value="<?=$_REQUEST[Verteiler_NR];?>"></td>
    </tr>
    <tr>
      <td bgcolor="#<? echo $webs[bgcolor_links] ?>" class="headline" width="20%" valign="top">An:<? echo $web_rechte[mail_verteiler][versenden][grundfunktionen]; ?></td>
      <td bgcolor="#<? echo $webs[bgcolor_rechts] ?>">
          <?
                $to=array();
                $query="
                        SELECT DISTINCT
                                Logins.E_Mail,
                                MD5(Logins.E_Mail) as MD5
                        FROM
                                Logins,
                                Logins_to_Verteiler
                        WHERE
                                Logins.ID = Logins_to_Verteiler.Logins
                        AND
                                Logins_to_Verteiler.Verteiler = '".$_REQUEST[Verteiler_NR]."'
                        ORDER BY
                                ID
                ";
                $result = mysql_query ($query) or die (mysql_errno().": ".mysql_error()."<hr>$query<hr>");
                $count = mysql_num_rows($result);
                while ($zeile=mysql_fetch_assoc($result)) 
                {
                        if (preg_match("/^[A-Za-z0-9-_.+]+\@[A-Za-z0-9-_.+]+\.[A-Za-z]+$/", $zeile[E_Mail]) > 0)
                        {
                                $to[$zeile[MD5]]=$zeile[E_Mail];
                        }
                }
          ?>
          <textarea name="To" cols="55" rows="10"><? echo implode(",\n",$to) ?></textarea>
          <br>
          Anzahl der ausgelesenen Empf&auml;nger:         <?=count($to);?>
          </td>
    </tr>
    <tr> 
      <td bgcolor="#<? echo $webs[bgcolor_links] ?>" class="headline" width="20%" valign="top">Absender:</td>
      <td bgcolor="#<? echo $webs[bgcolor_rechts] ?>"><? echo nl2br($Verteiler[$Verteiler_NR][Absender]) ?></td>
    </tr>
    <tr> 
      <td bgcolor="#<? echo $webs[bgcolor_links] ?>" class="headline" width="20%" valign="top">Betreff:</td>
      <td bgcolor="#<? echo $webs[bgcolor_rechts] ?>"><? echo nl2br($Verteiler[$Verteiler_NR][Betreff]) ?></td>
    </tr>
    <tr> 
      <td bgcolor="#<? echo $webs[bgcolor_links] ?>" class="headline" width="20%" valign="top">Begr&uuml;ssung:</td>
      <td bgcolor="#<? echo $webs[bgcolor_rechts] ?>"><? echo nl2br($Verteiler[$Verteiler_NR][Begruessung]) ?></td>
    </tr>
    <tr> 
      <td bgcolor="#<? echo $webs[bgcolor_links] ?>" class="headline" width="20%" valign="top">Text: 
        (Plain) </td>
      <td bgcolor="#<? echo $webs[bgcolor_rechts] ?>"> 
        <textarea name="message[PLAIN]" cols="100" rows="10" wrap="OFF"></textarea>
      </td>
    </tr>
        <tr> 
      <td bgcolor="#<? echo $webs[bgcolor_links] ?>" class="headline" width="20%" valign="top">Text: 
        (HTML) </td>
      <td bgcolor="#<? echo $webs[bgcolor_rechts] ?>"> 
        <textarea id=messageHTML name="message[HTML]" cols="100" rows="100" wrap="OFF">
<?
        if ($Verteiler[$_GET[Verteiler_NR]][Template_URL])
        {
?>
<p><?=nl2br($Verteiler[$Verteiler_NR][Begruessung])?></p>
<p></p>                                 
<? readfile($Verteiler[$_GET[Verteiler_NR]][Template_URL]);?>
<p></p>         
<p><?=nl2br($Verteiler[$Verteiler_NR][Schlusstext])?></p>
<?
        }
?>
                </textarea>
<script type="text/javascript">
        var config = new HTMLArea.Config();
        with (config)
        {
                width = '555';
                height = '500';
                statusBar=false;
                toolbar = 
                [
                        [
                                "fontname", "space", "fontsize", "space", "formatblock", "space",
                                "bold", "italic", "underline", "separator",
                                "strikethrough", "subscript", "superscript", "separator",
                                "copy", "cut", "paste", "separator", "undo", "redo"
                        ],
                        [
                                "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
                                "insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
                                "forecolor", "hilitecolor", "textindicator", "separator",
                                "inserthorizontalrule", "createlink", "insertimage", "htmlmode"
                        ]
                ];

                /*
                toolbar = 
                [
                        [
                                "fontname", "space", "fontsize", "space", "formatblock", "space",
                                "bold", "italic", "underline", "separator",
                                "strikethrough", "subscript", "superscript", "separator",
                                "copy", "cut", "paste", "space", "undo", "redo",
                                "separator", 
                                "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
                                "insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
                                "forecolor", "hilitecolor", "textindicator", "separator",
                                "inserthorizontalrule", "createlink", "insertimage", "htmlmode",
                        ]
                ];
                */
        }
        HTMLArea.replace("messageHTML",config);
</script>
      </td>
    </tr>
    <tr> 
      <td bgcolor="#<? echo $webs[bgcolor_links] ?>" class="headline" width="20%" valign="top">Schlusstext:</td>
      <td bgcolor="#<? echo $webs[bgcolor_rechts] ?>"><? echo nl2br($Verteiler[$Verteiler_NR][Schlusstext]) ?></td>
    </tr>
    <!--
    <tr> 
      <td bgcolor="#<? echo $webs[bgcolor_links] ?>" class="headline" valign="top" width="20%">Attachments:</td>
      <td bgcolor="#<? echo $webs[bgcolor_rechts] ?>"> 
        <input type="file" name="attach[]">
        <br>
        <input type="file" name="attach[]">
        <br>
        <input type="file" name="attach[]">
        <br>
        <input type="file" name="attach[]">
        <br>
        <input type="file" name="attach[]">
      </td>
    </tr>
-->
    <tr align="right"> 
      <td bgcolor="#<? echo $webs[bgcolor_links] ?>" class="headline" colspan="2"> 
        <input type="submit" name="action" value="Abschicken">
        <input type="reset" value="Zur&uuml;cksetzen">
      </td>
    </tr>
  </table>
</form>
</body>
</html>