290
|
1 <?php
|
|
2
|
|
3 /* Copyright (C) 2004 Christoph Thiel <ct at kki dot org>
|
|
4 *
|
|
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6 * of this software and associated documentation files (the "Software"), to
|
|
7 * deal in the Software without restriction, including without limitation the
|
|
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
9 * sell copies of the Software, and to permit persons to whom the Software is
|
|
10 * furnished to do so, subject to the following conditions:
|
|
11 *
|
|
12 * The above copyright notice and this permission notice shall be included in
|
|
13 * all copies or substantial portions of the Software.
|
|
14 *
|
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
21 * IN THE SOFTWARE.
|
|
22 */
|
|
23
|
|
24
|
|
25 // error_reporting(E_ALL);
|
|
26
|
|
27 class mlmmj
|
|
28 {
|
|
29 var $email;
|
|
30 var $mailinglist;
|
|
31 var $job;
|
|
32 var $redirect_success;
|
|
33 var $redirect_failure;
|
|
34
|
|
35 var $delimiter;
|
|
36 var $errors;
|
|
37
|
|
38 function is_email($string="")
|
|
39 {
|
|
40 if (eregi("^[a-z0-9\._-]+".chr(64)."+[a-z0-9\._-]+\.+[a-z]{2,4}$", $string))
|
|
41 {
|
|
42 return TRUE;
|
|
43 }
|
|
44 else
|
|
45 {
|
|
46 return FALSE;
|
|
47 }
|
|
48 }
|
|
49
|
|
50 function error($string="")
|
|
51 {
|
|
52 $this->errors = TRUE;
|
|
53 // die($string);
|
|
54 }
|
|
55
|
|
56 function mlmmj()
|
|
57 {
|
|
58 // set mandatory vars...
|
|
59 $this->errors = FALSE;
|
|
60 $this->delimiter = "+";
|
|
61
|
769
|
62 if (!isset($_POST["email"]) &&
|
|
63 !isset($_POST["mailinglist"]) &&
|
|
64 !isset($_POST["job"]) &&
|
|
65 !isset($_POST["redirect_success"]) &&
|
|
66 !isset($_POST["redirect_failure"]))
|
290
|
67 {
|
|
68 $this->errors = TRUE;
|
769
|
69 if(isset($_POST["redirect_failure"]))
|
290
|
70 {
|
769
|
71 header("Location: ".$_POST["redirect_failure"]);
|
290
|
72 exit;
|
|
73 }
|
|
74 else
|
|
75 die("An error occurred. Please check contrib/web/php-user/README for details.");
|
|
76 }
|
|
77 else
|
|
78 {
|
769
|
79 if($this->is_email($_POST["email"]))
|
|
80 $this->email = $_POST["email"];
|
290
|
81 else
|
|
82 $this->error("ERROR: email is not a valid email address.");
|
|
83
|
769
|
84 if($this->is_email($_POST["mailinglist"]))
|
|
85 $this->mailinglist = $_POST["mailinglist"];
|
290
|
86 else
|
|
87 $this->error("ERROR: mailinglist is not a valid email address.");
|
|
88
|
769
|
89 $this->job = $_POST["job"];
|
290
|
90
|
|
91 if(!(($this->job == "subscribe") OR ($this->job == "unsubscribe")))
|
|
92 {
|
|
93 $this->error("ERROR: job unknown.");
|
|
94 }
|
|
95
|
769
|
96 $this->redirect_failure = $_POST["redirect_failure"];
|
|
97 $this->redirect_success = $_POST["redirect_success"];
|
290
|
98
|
|
99 }
|
|
100
|
|
101 // now we should try to go ahead and {sub,unsub}scribe... ;)
|
|
102
|
|
103 if(!$this->errors)
|
|
104 {
|
|
105 // @ ^= char(64)
|
|
106
|
|
107 $to = str_replace(chr(64),$this->delimiter.$this->job.chr(64),$this->mailinglist);
|
|
108 $subject = $this->job." to ".$this->mailinglist;
|
|
109 $body = $this->job;
|
|
110 $addheader = "";
|
769
|
111 $addheader .= "Received: from ". $_SERVER["REMOTE_ADDR"]
|
|
112 ." by ". $_SERVER["SERVER_NAME"]. " with HTTP;\r\n\t".date("r")."\n";
|
|
113 $addheader .= "X-Originating-IP: ".$_SERVER["REMOTE_ADDR"]."\n";
|
290
|
114 $addheader .= "X-Mailer: mlmmj-webinterface powered by PHP/". phpversion() ."\n";
|
|
115 $addheader .= "From: ".$this->email."\n";
|
|
116 $addheader .= "Cc: ".$this->email."\n";
|
|
117
|
|
118 if(!mail($to, $subject, $body, $addheader))
|
|
119 $this->error($this->job." failed.");
|
|
120 }
|
|
121
|
|
122 if($this->errors)
|
|
123 {
|
|
124 header("Location: ".$this->redirect_failure);
|
|
125 exit;
|
|
126 }
|
|
127 else
|
|
128 {
|
|
129 header("Location: ".$this->redirect_success);
|
|
130 exit;
|
|
131 }
|
|
132 }
|
|
133 }
|
|
134
|
|
135
|
|
136 $mailinglist = new mlmmj;
|
|
137
|
|
138 ?>
|