Is dit script anti-spam?
Ik heb een mail script gemaakt en nu vroeg ik me af of het veilig is dat je geen spam krijgt.
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
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
<?php session_start();
if(!empty($_POST["send"])){
if(eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$_POST["email"]) && !empty($_POST["naam"]) && !empty($_POST["email"]) && !empty($_POST["onderwerp"]) && !empty($_POST["bericht"]) && $_POST["spam"] == $_SESSION["ant"]){
$naam = $_POST["naam"];
$email = $_POST["email"];
$onderwerp = $_POST["onderwerp"];
$bericht = $_POST["bericht"];
$ip = $_SERVER['REMOTE_ADDR'];
$bericht = wordwrap ($bericht, 40, "\n", 1);
// Headers
$headers = "From: ".$email.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset='iso-8859-1'\n";
// Bericht
$message = "Naam: ".$naam." \n";
$message .= "E-mail: ".$email." \n";
$message .= "Datum: ".date("d-m-Y H:i")." \n";
$message .= "------------------------------------------------------- \n";
$message .= $bericht."\n";
$message .= "------------------------------------------------------- \n";
$message .= "IP: ".$ip." \n ";
mail("[email protected]", $onderwerp, $message, $headers);
echo("<p>De mail is succesvol verzonden, ik doe mijn uiterste best hem zo snel mogelijk te behandelen!</p>");
session_destroy();
}
else{
$a = rand(6,10);
$b = rand(1,5);
$_SESSION["ant"] = $a - $b;
echo('
<p>Vul alle velden correct in!<br />
<form action="contact.php" method="POST">
<table>
<tr>
<td>Naam</td>
<td><input type="text" name="naam" size="30" value="'.$naam.'" maxlength="30"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" size="30" value="'.$email.'" maxlength="30"></td>
</tr>
<tr>
<td>Onderwerp</td>
<td><input type="text" name="onderwerp" size="30" value="'.$onderwerp.'" maxlength="30"></td>
</tr>
<tr>
<td>Bericht</td>
<td><textarea name="bericht" cols="40" rows="10">'.$bericht.'</textarea></td>
</tr>
<tr>
<td>'.$a.' - '.$b.' =</td>
<td><input type="text" name="spam" size="30" maxlength="1"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="send" value="Verstuur"></td>
</tr>
</table>
</form></p>');
}
}
else {
$a = rand(6,10);
$b = rand(1,5);
$_SESSION["ant"] = $a - $b;
echo ('
<p><form action="contact.php" method="POST">
<table>
<tr>
<td>Naam</td>
<td><input type="text" name="naam" size="30" maxlength="30"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" size="30" maxlength="30"></td>
</tr>
<tr>
<td>Onderwerp</td>
<td><input type="text" name="onderwerp" size="30" maxlength="30"></td>
</tr>
<tr>
<td>Bericht</td>
<td><textarea name="bericht" cols="40" rows="10"></textarea></td>
</tr>
<tr>
<td>'.$a.' - '.$b.' =</td>
<td><input type="text" name="spam" size="30" maxlength="1"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="send" value="Verstuur"></td>
</tr>
</table>
</form></p>
'); } ?>
if(!empty($_POST["send"])){
if(eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$_POST["email"]) && !empty($_POST["naam"]) && !empty($_POST["email"]) && !empty($_POST["onderwerp"]) && !empty($_POST["bericht"]) && $_POST["spam"] == $_SESSION["ant"]){
$naam = $_POST["naam"];
$email = $_POST["email"];
$onderwerp = $_POST["onderwerp"];
$bericht = $_POST["bericht"];
$ip = $_SERVER['REMOTE_ADDR'];
$bericht = wordwrap ($bericht, 40, "\n", 1);
// Headers
$headers = "From: ".$email.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset='iso-8859-1'\n";
// Bericht
$message = "Naam: ".$naam." \n";
$message .= "E-mail: ".$email." \n";
$message .= "Datum: ".date("d-m-Y H:i")." \n";
$message .= "------------------------------------------------------- \n";
$message .= $bericht."\n";
$message .= "------------------------------------------------------- \n";
$message .= "IP: ".$ip." \n ";
mail("[email protected]", $onderwerp, $message, $headers);
echo("<p>De mail is succesvol verzonden, ik doe mijn uiterste best hem zo snel mogelijk te behandelen!</p>");
session_destroy();
}
else{
$a = rand(6,10);
$b = rand(1,5);
$_SESSION["ant"] = $a - $b;
echo('
<p>Vul alle velden correct in!<br />
<form action="contact.php" method="POST">
<table>
<tr>
<td>Naam</td>
<td><input type="text" name="naam" size="30" value="'.$naam.'" maxlength="30"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" size="30" value="'.$email.'" maxlength="30"></td>
</tr>
<tr>
<td>Onderwerp</td>
<td><input type="text" name="onderwerp" size="30" value="'.$onderwerp.'" maxlength="30"></td>
</tr>
<tr>
<td>Bericht</td>
<td><textarea name="bericht" cols="40" rows="10">'.$bericht.'</textarea></td>
</tr>
<tr>
<td>'.$a.' - '.$b.' =</td>
<td><input type="text" name="spam" size="30" maxlength="1"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="send" value="Verstuur"></td>
</tr>
</table>
</form></p>');
}
}
else {
$a = rand(6,10);
$b = rand(1,5);
$_SESSION["ant"] = $a - $b;
echo ('
<p><form action="contact.php" method="POST">
<table>
<tr>
<td>Naam</td>
<td><input type="text" name="naam" size="30" maxlength="30"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" size="30" maxlength="30"></td>
</tr>
<tr>
<td>Onderwerp</td>
<td><input type="text" name="onderwerp" size="30" maxlength="30"></td>
</tr>
<tr>
<td>Bericht</td>
<td><textarea name="bericht" cols="40" rows="10"></textarea></td>
</tr>
<tr>
<td>'.$a.' - '.$b.' =</td>
<td><input type="text" name="spam" size="30" maxlength="1"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="send" value="Verstuur"></td>
</tr>
</table>
</form></p>
'); } ?>
Gewijzigd op 01/01/1970 01:00:00 door Matshofman
Daar begint het al, dat zou ik al anders doen.
Nee, dit script is gevoelig voor email-injection.
dit zou het leuk zijn.. Dan kun je zo een paar duizend mailtjes versturen..
ICM