Mail Notificatie maximaal eenmaal per 4 uur

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

JunkieXP

JunkieXP

25/09/2008 14:17:00
Quote Anchor link
Ik ben al tijden bezig om deze functionaliteit werkend te krijgen, het principe is simpel, er wordt gecontroleerd of de datum van plaatsing post 4u verwijderd ligt van de vorige post. Wanneer dit het geval is veranderd de inhoud van de TXT file en mag de mail verzonden worden, zo niet blijft deze gelijk en mag er geen mail verzonden worden om eventuele drukte niet opgevolgd te laten worden door een notificatie mailbom.

De inhoud van het TXT bestand veranderd wel, maar ookal heb ik een variabele false meegegeven de mail wordt alsnog verzonden, ik heb al vele veranderingen geprobeer echter blijkt er tot dusver geen een succesvol te zijn.

Dit is de functionaliteit welke de mailnotificatie uitvoert.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
*This Function Sends an E-Mail to all interested Team Members.
*/

function MailNotification($mailType = '', $directLink = '', $postName = 'Een zeker persoon', $postMail = '', $postMessage = ''){
    function
TimeSinceLastPost($tableType, $resetTimer){
        if(!empty($tableType)){
            $timeStamp_sql = mysql_query("SELECT UNIX_TIMESTAMP(date) AS TimeStamp FROM ".$tableType." ORDER BY date DESC LIMIT 0, 1");
                        
                        while($timeStamp_whl = mysql_fetch_array($timeStamp_sql)){
                            $timeLastPost = $timeStamp_whl['TimeStamp'];
                        }

            
            //GetCurrent Betweentime
            $fileLocation = "timestamp.txt";
            $fileDisplayHandler = fopen($fileLocation, 'r');
            $fileDisplay = fgets($fileDisplayHandler);
            
            //Current Time minus Last Logged time.
            $timeSinceLastPost = (time() - $fileDisplay) / 3600;

            //If Time since last post reaches a certain time, then send mail and write timeLastPost to file.
            if($timeSinceLastPost >= $resetTimer){
                $fileOverwriteHandler = fopen($fileLocation, 'w+');
                $fileOverwrite = fwrite($fileOverwriteHandler, time());
                fclose($fileOverwriteHandler);
                
                $sendMail = true;
            }
else{
                $sendMail = false;
            }
        }

    fclose($fileDisplayHandler);

return $sendMail;
    }

    
    //Strip Slashes
    $postMessage = stripslashes($postMessage);
        
    if($mailType == "guestbook"){
        $tableType = "gbook";
        $resetTimer = 4;
        
        //This Creates an Array with all the Subscribed members who wanted a Notice.
        $arrRecipients = array("Webmaster Nr. 1" => "[email protected]");
        
        //This contains the Subject and the Whole Message.
        $subject        = "Nieuw Bericht (Gastenboek)";

        $message        = "<html>";
        $message        .= "<body style=\"font-family:'tahoma', monospace; font-size:10pt;\">";
        $message        .= "<h3>Nieuw Gastenboek Bericht</h3>";
        $message        .= $postName." heeft een nieuw bericht geplaatst in het gastenboek, dit is een klein stukje uit dat bericht: <br /><br />";
        $message        .= $postMessage."...<br /><br />Wil je het complete bericht lezen, klik dan op de link.<br /><br />";
        $message        .= "<a href=\"http://Incredibles.nl/gastenboek/\" target=\"_blank\">[Zv. the Incredibles] Gastenboek</a><br /><br />";
        
    }
else if($mailType == "news"){
        $tableType = "news";
        $resetTimer = 0;
        
        //This Creates an Array with all the Subscribed members who wanted a Notice.
        $arrRecipients = array("Webmaster Nr. 1" => "[email protected]");
        
        //This contains the Subject and the Whole Message.
        $subject        = "Nieuwsitem Toegevoegd";

        $message        = "<html>";
        $message        .= "<body style=\"font-family:'tahoma', monospace; font-size:10pt;\">";
        $message        .= "<h3>Nieuwsitem Toegevoegd</h3>";
        $message        .= $postName." heeft een zojuist een nieuw nieuwsitem toegevoegd, dit is een klein stukje van dat item: <br /><br />";
        $message        .= $postMessage."...<br /><br />Wil je het complete nieuwsitem lezen, klik dan op de link.<br /><br />";
        $message        .= "<a href=\"http://Incredibles.nl/\" target=\"_blank\">[Zv. the Incredibles] StartPagina</a><br /><br />";
    }

    
    //Anti Spam Timer
    $mailAllowed = TimeSinceLastPost($tableType, $resetTimer);
    
        //Send Notification Mail
        if($mailAllowed){
            $fromName         = "Zv. the Incredibles Mailing";
            $fromMail         = "[email protected]";
            
            $i = 1;
            while(count($arrRecipients) >= $i){
             $RecipientsName = key($arrRecipients);
             $RecipientsMail = $arrRecipients[key($arrRecipients)];
            
             if(strtolower($postMail) != strtolower($RecipientsMail)){
              if(count($arrRecipients) == $i){
               $recipients .= "\"".$RecipientsName."\" <".$RecipientsMail.">";
              }
else{
               $recipients .= "\"".$RecipientsName."\" <".$RecipientsMail.">, ";
              }
             }
else{
              //No Action
             }
            
            next($arrRecipients);
            $i++;
            }


            $message        .= "Groeten,<br />Webmaster Zv. the Incredibles<br /><br />";
            $message        .= "<font style=\"font-size:8pt;\">Wanneer je niet langer berichtgeving wenst te ontvangen over nieuwe bijdrage op de Site kun je contact opnemen met de WebMaster.</font>";
            $message        .= "</body>";
            $message        .= "</html>";
            
            $headers         = "From: ".$fromName." <".$fromMail.">\r\n";
            $headers         .= "MIME-Version: 1.0\r\n";
            $headers         .= "Content-type: text/html; charset=utf-8\r\n";

            mail($recipients, $subject, $message, $headers);
        }
else{
            //Do not Send a Notification Mail.
        }
}

?>
Gewijzigd op 01/01/1970 01:00:00 door JunkieXP
 
PHP hulp

PHP hulp

29/03/2024 09:18:26
 
- SanThe -

- SanThe -

25/09/2008 14:26:00
Quote Anchor link
Een function in een function.?
 
JunkieXP

JunkieXP

25/09/2008 15:10:00
Quote Anchor link
Gezien die functie enkel en alleen in die functie gebruikt dient te worden zag ik het probleem hier niet van in en bleef de code overzichtelijk, natuurlijk is deze manier van handelen niet optimaal.
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.