contact.php
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
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
<!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" xml:lang="en">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<title>contact script</title>
</head>
<body>
<?php
//instellingen
$email_host = ''; //mail.bedrijf.nl
$email_naam = ''; //admin , bedrijf
$email_adres = ''; // [email protected]
$website = ''; // website url
$ban = array('0.0.0.0', '0.0.0.0', '0.0.0.0' ); // ban een IP , meer IP'S toevoegen kan door ,'' toetevoegen
if (in_array($_SERVER['REMOTE_ADDR'], $ban, true)) {
echo "Verbannen via IP";
} else {
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$error = array();
if($_POST['naam'] == '') {
$error[0] = TRUE;
}
if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])\?*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email'])) {
$error[1] = TRUE;
}
if($_POST['onderwerp'] == '') {
$error[2] = TRUE;
}
if($_POST['bericht'] == '') {
$error[3] = TRUE;
}
if( !isset($error ) ) {
//SWIFTMAILER
require_once 'lib/swift_required.php';
$mailer = new Swift_Mailer(new Swift_SmtpTransport($email_host));
$message = Swift_Message::newInstance($_POST['onderwerp'], 'Verstuurd vanaf het contact form op '.$website.' <br /><br />Van het ipadres: '.$_SERVER['SERVER_ADDR'].'<br />bericht:<br /><br />'.nl2br(htmlentries($_POST['bericht'])))
->setFrom(array($_POST['email'] => $_POST['naam']))
->setTo(array($email_adres => $email_naam))
->setContentType('text/html');
$mailer->send($message);
$title = 'Er is succesvol een email gestuurd!';
$text = 'Bedankt , Uw email is verzonden<br />Uw bericht zal gelezen worden en zo spoedig mogelijk worden beantwoord.';
}
}
if($title) {
Echo '<h1>'.$title.'</h1><br /><br />';
} Else {
Echo '<h1>Contact</h1>';
}
if($text) {
Echo $text;
} else {
if($error) {
Echo '<font color=#ff0000><b>Er is iets misgegaan , Check de velden in het rood!<br /></b></font>';
}
?>
<form method="post" action=''>
<table border="0" cellpadding="0" cellspacing="10">
<tr>
<td width="161" valign="top">
<strong>Naam:</strong>
</td>
<td width="477">
<input name="naam" OnKeyPress="this.style.cssText='border: 2px solid black;'" type="text" style="border: 2px solid
<?php if($error[0]) { Echo 'red'; }else { Echo 'black'; } ?>;" size="50" />
</td>
</tr>
<tr>
<td valign="top">
<strong>E-mail adres:</strong>
</td>
<td>
<input name="email" OnKeyPress= "this.style.cssText='border:2px solid black;'" type="text" style="border: 2px solid
<?php if($error[1]) { Echo 'red'; }else { Echo 'black'; } ?>;" value="" size="50" />
</td>
</tr>
<tr>
<td valign="top">
<strong>Onderwerp:</strong>
</td>
<td>
<input name="onderwerp" OnKeyPress= "this.style.cssText='border: 2px solid black;'" type="text" style="border: 2px solid
<?php if($error[2]) { Echo 'red'; }else { Echo 'black'; } ?>;" value="" size="50" />
</td>
</tr>
<tr>
<td valign="top">
<strong>Bericht:</strong>
</td>
<td>
<textarea name="bericht" cols="50" rows="10" OnKeyPress="this.style.cssText='border: 2px solid black;'" style="border: 2px solid
<?php if($error[3]) { Echo 'red'; }else { Echo 'black'; } ?>;" ></textarea>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<input name="submit" type="submit" value="Verstuur" />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<title>contact script</title>
</head>
<body>
<?php
//instellingen
$email_host = ''; //mail.bedrijf.nl
$email_naam = ''; //admin , bedrijf
$email_adres = ''; // [email protected]
$website = ''; // website url
$ban = array('0.0.0.0', '0.0.0.0', '0.0.0.0' ); // ban een IP , meer IP'S toevoegen kan door ,'' toetevoegen
if (in_array($_SERVER['REMOTE_ADDR'], $ban, true)) {
echo "Verbannen via IP";
} else {
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$error = array();
if($_POST['naam'] == '') {
$error[0] = TRUE;
}
if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])\?*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email'])) {
$error[1] = TRUE;
}
if($_POST['onderwerp'] == '') {
$error[2] = TRUE;
}
if($_POST['bericht'] == '') {
$error[3] = TRUE;
}
if( !isset($error ) ) {
//SWIFTMAILER
require_once 'lib/swift_required.php';
$mailer = new Swift_Mailer(new Swift_SmtpTransport($email_host));
$message = Swift_Message::newInstance($_POST['onderwerp'], 'Verstuurd vanaf het contact form op '.$website.' <br /><br />Van het ipadres: '.$_SERVER['SERVER_ADDR'].'<br />bericht:<br /><br />'.nl2br(htmlentries($_POST['bericht'])))
->setFrom(array($_POST['email'] => $_POST['naam']))
->setTo(array($email_adres => $email_naam))
->setContentType('text/html');
$mailer->send($message);
$title = 'Er is succesvol een email gestuurd!';
$text = 'Bedankt , Uw email is verzonden<br />Uw bericht zal gelezen worden en zo spoedig mogelijk worden beantwoord.';
}
}
if($title) {
Echo '<h1>'.$title.'</h1><br /><br />';
} Else {
Echo '<h1>Contact</h1>';
}
if($text) {
Echo $text;
} else {
if($error) {
Echo '<font color=#ff0000><b>Er is iets misgegaan , Check de velden in het rood!<br /></b></font>';
}
?>
<form method="post" action=''>
<table border="0" cellpadding="0" cellspacing="10">
<tr>
<td width="161" valign="top">
<strong>Naam:</strong>
</td>
<td width="477">
<input name="naam" OnKeyPress="this.style.cssText='border: 2px solid black;'" type="text" style="border: 2px solid
<?php if($error[0]) { Echo 'red'; }else { Echo 'black'; } ?>;" size="50" />
</td>
</tr>
<tr>
<td valign="top">
<strong>E-mail adres:</strong>
</td>
<td>
<input name="email" OnKeyPress= "this.style.cssText='border:2px solid black;'" type="text" style="border: 2px solid
<?php if($error[1]) { Echo 'red'; }else { Echo 'black'; } ?>;" value="" size="50" />
</td>
</tr>
<tr>
<td valign="top">
<strong>Onderwerp:</strong>
</td>
<td>
<input name="onderwerp" OnKeyPress= "this.style.cssText='border: 2px solid black;'" type="text" style="border: 2px solid
<?php if($error[2]) { Echo 'red'; }else { Echo 'black'; } ?>;" value="" size="50" />
</td>
</tr>
<tr>
<td valign="top">
<strong>Bericht:</strong>
</td>
<td>
<textarea name="bericht" cols="50" rows="10" OnKeyPress="this.style.cssText='border: 2px solid black;'" style="border: 2px solid
<?php if($error[3]) { Echo 'red'; }else { Echo 'black'; } ?>;" ></textarea>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<input name="submit" type="submit" value="Verstuur" />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
}
?>