Nieuwsbrief verzend 2x
maar nu heb ik een probleem elke mail verzend deze 2x de koper waar ik het aan gekocht heb antwoord zijn mails niet dus ik hoop dat jullie me kunnen helpen
Code (php)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
// verbinding met database vanuit de include
include_once('includes/conn.inc.php');
$server = 'mijnwebsite'; // Domein waar script bevind.
function email($to, $subject, $content, $server, $hash)
{
$from = 'emailadresvanadministrator'; // E-mail
$path = './template.html';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'To: ' . $to . '' . "\r\n";
$headers .= 'From: ' . $from . '' . "\r\n";
$template = file_get_contents($path);
$template = str_replace('{{content}}',$content,$template);
$template = str_replace('{{footer}}','U kunt afmelden door middel van deze link: ' . $server . '/signoff.php?code=' . $hash,$template);
if(mail($to,$subject,$template,$headers))
{
return true;
}
else
{
return false;
}
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SimpleNews</title>
<style type="text/css">
<!--
body
{
background: #F7F7F7;
font-family: Verdana, Geneva, sans-serif;
font-size: 14px;
color: #333;
}
h2
{
border-bottom: 2px solid #ccc;
width: 500px;
}
input
{
font-family: Verdana, Geneva, sans-serif;
font-size: 14px;
color: #333;
padding: 3px;
}
fieldset, legend
{
border: 0;
padding: 0;
margin: 0;
}
fieldset
{
margin-bottom: 10px;
}
-->
</style>
<!-- TinyMCE -->
<script type="text/javascript" src="/demo-nieuwsbrief/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example word content CSS (should be your site CSS) this one removes paragraph margins
content_css : "css/word.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
});
</script>
<!-- /TinyMCE -->
<script>
//==========================================
// Check All boxes
//==========================================
function CheckAll(fmobj)
{
for (var i=0;i<fmobj.elements.length;i++)
{
var e = fmobj.elements[i];
if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled))
{
e.checked = fmobj.allbox.checked;
}
}
}
//==========================================
// Check all or uncheck all?
//==========================================
function CheckCheckAll(fmobj)
{
var TotalBoxes = 0;
var TotalOn = 0;
for (var i=0;i<fmobj.elements.length;i++)
{
var e = fmobj.elements[i];
if ((e.name != 'allbox') && (e.type=='checkbox'))
{
TotalBoxes++;
if (e.checked)
{
TotalOn++;
}
}
}
if (TotalBoxes==TotalOn)
{
fmobj.allbox.checked=true;
}
else
{
fmobj.allbox.checked=false;
}
}
</script>
</head>
<body>
<h2>Nieuwsbrief versturen</h2>
<?php
$juist = true;
if(isset($juist))
{
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_POST['subject']) && empty($_POST['subject']))
{
echo '<b>Je onderwerp is leeggelaten, <a href="/massmail.php">ga terug</a>.</b>';
}
elseif(isset($_POST['message']) && empty($_POST['message']))
{
echo '<b>Je bericht is leeggelaten, <a href="/massmail.php">ga terug</a>.</b>';
}
elseif(!ctype_alnum(str_replace(' ', '', $_POST['subject'])))
{
echo '<b>Je onderwerp heeft geen geldige charackers, <a href="/massmail.php">ga terug</a>.</b>';
}
else
{
if(!isset($_POST['delAnn']))
{
echo '<b>Er moet wel een bericht naar iemand toe worden gestuurd, <a href="/massmail.php">ga terug</a>.</b>';
}
else
{
foreach($_POST['delAnn'] as $id => $user)
{
$query = $mysqli->query("SELECT * FROM users WHERE id='" . $user . "'");
if(mysqli_num_rows($query) > 0)
{
$emails = '';
$row = mysqli_fetch_assoc($query);
email($row['realname'] . ' <' . $row['email'] . '>', $_POST['subject'], $_POST['message'], $server, $row['hash']);
sleep(1);
echo 'Mail verstuurd naar ' . $row['email'] . '.<br />';
}
}
echo '<br /><b>U heeft met success iedereen een e-mail verstuurd, <a href="/massmail.php">ga terug</a>.</b>';
}
}
}
else
{
?>
<form name="trackunread" id="form" method="post" action="">
<table style="margin-bottom: 10px; border-bottom: 2px solid #ccc;" width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input style="border:inset 1px;" name="allbox" type="checkbox" value="Check All" onclick="CheckAll(document.trackunread);" /></td>
<td><b>Naam</b></td>
<td><b>E-mail</b></td>
</tr>
<tr>
<td></td>
<td> </td>
<td> </td>
</tr>
<?php
$query = $mysqli->query("SELECT * FROM mailsuers");
if(mysqli_num_rows($query) > 0)
{
while($row = mysqli_fetch_assoc($query))
{
?>
<tr>
<td><input class="boxes" type="checkbox" id="check<?php echo $row['id']; ?>" value="<?php echo $row['id']; ?>" name="delAnn[]" /></td> </td>
<td width="150"><label for="check<?php echo $row['id']; ?>"><?php echo $row['realname']; ?></label></td>
<td><?php echo $row['email']; ?></td>
</tr>
<?php
}
}
?>
<tr>
<td></td>
<td> </td>
<td> </td>
</tr>
</table>
<fieldset>
<legend>Onderwerp:</legend>
<input name="subject" type="text" size="35" maxlength="150" />
</fieldset>
<fieldset>
<legend>Bericht:</legend>
<textarea name="message" cols="45" rows="10"></textarea>
</fieldset>
<fieldset>
<input type="submit" value=" Versturen " onclick="this.value=' Moment... ';" />
</fieldset>
</form>
<?php
}
}
else
{
echo '<b>Helaas geen toegang.</b>';
}
?>
</body>
</html>
// verbinding met database vanuit de include
include_once('includes/conn.inc.php');
$server = 'mijnwebsite'; // Domein waar script bevind.
function email($to, $subject, $content, $server, $hash)
{
$from = 'emailadresvanadministrator'; // E-mail
$path = './template.html';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'To: ' . $to . '' . "\r\n";
$headers .= 'From: ' . $from . '' . "\r\n";
$template = file_get_contents($path);
$template = str_replace('{{content}}',$content,$template);
$template = str_replace('{{footer}}','U kunt afmelden door middel van deze link: ' . $server . '/signoff.php?code=' . $hash,$template);
if(mail($to,$subject,$template,$headers))
{
return true;
}
else
{
return false;
}
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SimpleNews</title>
<style type="text/css">
<!--
body
{
background: #F7F7F7;
font-family: Verdana, Geneva, sans-serif;
font-size: 14px;
color: #333;
}
h2
{
border-bottom: 2px solid #ccc;
width: 500px;
}
input
{
font-family: Verdana, Geneva, sans-serif;
font-size: 14px;
color: #333;
padding: 3px;
}
fieldset, legend
{
border: 0;
padding: 0;
margin: 0;
}
fieldset
{
margin-bottom: 10px;
}
-->
</style>
<!-- TinyMCE -->
<script type="text/javascript" src="/demo-nieuwsbrief/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example word content CSS (should be your site CSS) this one removes paragraph margins
content_css : "css/word.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
});
</script>
<!-- /TinyMCE -->
<script>
//==========================================
// Check All boxes
//==========================================
function CheckAll(fmobj)
{
for (var i=0;i<fmobj.elements.length;i++)
{
var e = fmobj.elements[i];
if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled))
{
e.checked = fmobj.allbox.checked;
}
}
}
//==========================================
// Check all or uncheck all?
//==========================================
function CheckCheckAll(fmobj)
{
var TotalBoxes = 0;
var TotalOn = 0;
for (var i=0;i<fmobj.elements.length;i++)
{
var e = fmobj.elements[i];
if ((e.name != 'allbox') && (e.type=='checkbox'))
{
TotalBoxes++;
if (e.checked)
{
TotalOn++;
}
}
}
if (TotalBoxes==TotalOn)
{
fmobj.allbox.checked=true;
}
else
{
fmobj.allbox.checked=false;
}
}
</script>
</head>
<body>
<h2>Nieuwsbrief versturen</h2>
<?php
$juist = true;
if(isset($juist))
{
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_POST['subject']) && empty($_POST['subject']))
{
echo '<b>Je onderwerp is leeggelaten, <a href="/massmail.php">ga terug</a>.</b>';
}
elseif(isset($_POST['message']) && empty($_POST['message']))
{
echo '<b>Je bericht is leeggelaten, <a href="/massmail.php">ga terug</a>.</b>';
}
elseif(!ctype_alnum(str_replace(' ', '', $_POST['subject'])))
{
echo '<b>Je onderwerp heeft geen geldige charackers, <a href="/massmail.php">ga terug</a>.</b>';
}
else
{
if(!isset($_POST['delAnn']))
{
echo '<b>Er moet wel een bericht naar iemand toe worden gestuurd, <a href="/massmail.php">ga terug</a>.</b>';
}
else
{
foreach($_POST['delAnn'] as $id => $user)
{
$query = $mysqli->query("SELECT * FROM users WHERE id='" . $user . "'");
if(mysqli_num_rows($query) > 0)
{
$emails = '';
$row = mysqli_fetch_assoc($query);
email($row['realname'] . ' <' . $row['email'] . '>', $_POST['subject'], $_POST['message'], $server, $row['hash']);
sleep(1);
echo 'Mail verstuurd naar ' . $row['email'] . '.<br />';
}
}
echo '<br /><b>U heeft met success iedereen een e-mail verstuurd, <a href="/massmail.php">ga terug</a>.</b>';
}
}
}
else
{
?>
<form name="trackunread" id="form" method="post" action="">
<table style="margin-bottom: 10px; border-bottom: 2px solid #ccc;" width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input style="border:inset 1px;" name="allbox" type="checkbox" value="Check All" onclick="CheckAll(document.trackunread);" /></td>
<td><b>Naam</b></td>
<td><b>E-mail</b></td>
</tr>
<tr>
<td></td>
<td> </td>
<td> </td>
</tr>
<?php
$query = $mysqli->query("SELECT * FROM mailsuers");
if(mysqli_num_rows($query) > 0)
{
while($row = mysqli_fetch_assoc($query))
{
?>
<tr>
<td><input class="boxes" type="checkbox" id="check<?php echo $row['id']; ?>" value="<?php echo $row['id']; ?>" name="delAnn[]" /></td> </td>
<td width="150"><label for="check<?php echo $row['id']; ?>"><?php echo $row['realname']; ?></label></td>
<td><?php echo $row['email']; ?></td>
</tr>
<?php
}
}
?>
<tr>
<td></td>
<td> </td>
<td> </td>
</tr>
</table>
<fieldset>
<legend>Onderwerp:</legend>
<input name="subject" type="text" size="35" maxlength="150" />
</fieldset>
<fieldset>
<legend>Bericht:</legend>
<textarea name="message" cols="45" rows="10"></textarea>
</fieldset>
<fieldset>
<input type="submit" value=" Versturen " onclick="this.value=' Moment... ';" />
</fieldset>
</form>
<?php
}
}
else
{
echo '<b>Helaas geen toegang.</b>';
}
?>
</body>
</html>
Wat ik wel zie is dat je query's niet veilig zijn => SQL-Injection. En de headers van de mail zijn ook niet correct.
http://phpwiki.santhe.nl/index.php/De_juiste_mailheaders
ik krijg de indruk dat er zoveel mail wordt verstuurd als er entries zijn aangevinkt; en het formulier met de vinkjes wordt opgebouwd uit de tabel "mailsuers" (heet die echt zo? Charmante tikfout, of begrip dat ik nog niet ken?)