email-formulier-generator
Gesponsorde koppelingen
PHP script bestanden
Voorbeeld van een gegenereerd formulier, ik heb de volgende gegevens ingevuld:
E-mailadres ontvanger: "[email protected]"
E-mailadres afzender: "[email protected]"
E-mail onderwerp: "Formuliergegevens van www.php-solutions.nl"
Velden:
Naam, textfield, Martijn, , verplicht
E-mail, textfield, , , niet verplicht
Vraag, textarea, , , verplicht
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
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
<?php
if(function_exists('date_default_timezone_set')) { date_default_timezone_set('Europe/Amsterdam'); }
define('LF', "\n");
// Get a value from the $_POST array (case insensitive!!)
function getPost($key, $trim = false, $lowercase = false, $int = false)
{
if(isset($_POST[$key]))
{
$v = stripslashes($_POST[$key]);
if($trim)
{
$v = trim($v);
}
if($int)
{
$v = intval($v);
}
elseif($lowercase)
{
$v = strtolower($v);
}
return $v;
}
return '';
}
// Default values
$field_1 = 'Martijn';
$field_2 = '';
$field_3 = '';
$sHtml = '';
$sFormError = '';
// Process form
if(empty($_POST['form']) == false)
{
$field_1 = getPost('field_1', true);
if(strlen($field_1) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
$field_2 = getPost('field_2', true);
$field_3 = getPost('field_3', true);
if(strlen($field_3) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
}
// Show form
if(empty($_POST['form']) || $sFormError)
{
$sHtml .= '<form action="" method="post">
<input name="form" type="hidden" value="form1">
<h1>Vul a.u.b. het onderstaande formulier in</h1>
' . $sFormError . '
<table border="0" cellpadding="3" cellspacing="0"><tr>
<td align="left" class="label" valign="top">Naam *</td>
<td align="left" class="input" valign="top"><input name="field_1" type="text" value="' . htmlentities($field_1) . '"></td>
</tr>
<tr>
<td align="left" class="label" valign="top">Email</td>
<td align="left" class="input" valign="top"><input name="field_2" type="text" value="' . htmlentities($field_2) . '"></td>
</tr>
<tr>
<td align="left" class="label" valign="top">Opmerking *</td>
<td align="left" class="input" valign="top"><textarea name="field_3">' . htmlentities($field_3) . '</textarea></td>
</tr>
<tr>
<td align="left" class="text" valign="top"> </td>
<td align="left" class="input" valign="top"><input type="submit" value="Verzenden"></td>
</table>
</form>';
}
else // Send form
{
$mail_to = '[email protected]';
$mail_from = '[email protected]';
$mail_subject = 'Formuliergegevens van www.php-solutions.nl';
$mail_message = 'Formuliergegevens: ' . LF . LF
. 'Naam: ' . $field_1 . LF
. 'Email: ' . $field_2 . LF
. 'Opmerking: ' . $field_3 . LF
. LF
. 'IP: ' . $_SERVER['REMOTE_ADDR'] . ', Datum: ' . date('d-m-Y') . ', Tijd: ' . date('H:i:s');
mail($mail_to, $mail_subject, $mail_message, 'From: ' . $mail_from);
$sHtml .= '<h1>Formulier verzonden</h1><p>Hartelijk dank voor het invullen van het formulier.</p>';
}
echo $sHtml;
?>
if(function_exists('date_default_timezone_set')) { date_default_timezone_set('Europe/Amsterdam'); }
define('LF', "\n");
// Get a value from the $_POST array (case insensitive!!)
function getPost($key, $trim = false, $lowercase = false, $int = false)
{
if(isset($_POST[$key]))
{
$v = stripslashes($_POST[$key]);
if($trim)
{
$v = trim($v);
}
if($int)
{
$v = intval($v);
}
elseif($lowercase)
{
$v = strtolower($v);
}
return $v;
}
return '';
}
// Default values
$field_1 = 'Martijn';
$field_2 = '';
$field_3 = '';
$sHtml = '';
$sFormError = '';
// Process form
if(empty($_POST['form']) == false)
{
$field_1 = getPost('field_1', true);
if(strlen($field_1) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
$field_2 = getPost('field_2', true);
$field_3 = getPost('field_3', true);
if(strlen($field_3) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
}
// Show form
if(empty($_POST['form']) || $sFormError)
{
$sHtml .= '<form action="" method="post">
<input name="form" type="hidden" value="form1">
<h1>Vul a.u.b. het onderstaande formulier in</h1>
' . $sFormError . '
<table border="0" cellpadding="3" cellspacing="0"><tr>
<td align="left" class="label" valign="top">Naam *</td>
<td align="left" class="input" valign="top"><input name="field_1" type="text" value="' . htmlentities($field_1) . '"></td>
</tr>
<tr>
<td align="left" class="label" valign="top">Email</td>
<td align="left" class="input" valign="top"><input name="field_2" type="text" value="' . htmlentities($field_2) . '"></td>
</tr>
<tr>
<td align="left" class="label" valign="top">Opmerking *</td>
<td align="left" class="input" valign="top"><textarea name="field_3">' . htmlentities($field_3) . '</textarea></td>
</tr>
<tr>
<td align="left" class="text" valign="top"> </td>
<td align="left" class="input" valign="top"><input type="submit" value="Verzenden"></td>
</table>
</form>';
}
else // Send form
{
$mail_to = '[email protected]';
$mail_from = '[email protected]';
$mail_subject = 'Formuliergegevens van www.php-solutions.nl';
$mail_message = 'Formuliergegevens: ' . LF . LF
. 'Naam: ' . $field_1 . LF
. 'Email: ' . $field_2 . LF
. 'Opmerking: ' . $field_3 . LF
. LF
. 'IP: ' . $_SERVER['REMOTE_ADDR'] . ', Datum: ' . date('d-m-Y') . ', Tijd: ' . date('H:i:s');
mail($mail_to, $mail_subject, $mail_message, 'From: ' . $mail_from);
$sHtml .= '<h1>Formulier verzonden</h1><p>Hartelijk dank voor het invullen van het formulier.</p>';
}
echo $sHtml;
?>