hulp gevraagd met code webformulier
ik ben bezig met het maken van een webformulier.
ik heb wat code gevonden op internet en het werkt deels.
wie kan mij echter helpen met onderstaande punten?
1. als inhoud van de mail krijg ik enkel de inhoud van het commentaarvak.
ik wil er ook de inhoud van 'datum genomen' en 'plaats genomen' bij zien.
2. ik kan slechts één bestand (foto) verzenden. Wie kan mij helpen om ook een tweede bestand (foto) te kunnen bijvoegen.
hieronder staat de volledige code van het webformulier.
alvast met dank,
ErikVI
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
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
<?php
// E-mail adres waar de form naartoe zal worden gestuurd:
$mailto = "[email protected]";
# Maximum grootte van het attachment in bytes:
$max_attach_size = 500000;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Formmailer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
// Actie als op de knop 'verzenden' wordt gedrukt
if (isset($_POST["form_submitted"])){
// zal in de mail toekomen als 'afzender'. Hier naam en voornaam van het lid
$name = $_POST['name'];
//$email = $_POST['email'];
// zal in de mail toekomen als 'onderwerp'
$subject = $_POST['subject'];
// zal in de mail toekomen als 'inhoud'
$date = $_POST['date'];
$place = $_POST['place'];
$text = $_POST['text'];
// weergeven van fouten
unset($errors);
$mail_name=$name;
$mail_subject = "mail vanuit webformulier";
$ip = $_SERVER["REMOTE_ADDR"];
// if attachment, MIME-Mail:
if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != ""){
// read and encode file:
$datei_content = fread(fopen($_FILES['probe']['tmp_name'],"r"),
filesize($_FILES['probe']['tmp_name']));
$datei_content = chunk_split(base64_encode($datei_content),76,"\n");
// Boundary:
$boundary = md5(uniqid(rand()));
// Mail-Header:
$mail_header = "From: ".$mail_name." <".$mail_email.">\n";
$mail_header .= "X-Sender-IP: ".$ip."\n";
$mail_header .= "MIME-Version: 1.0\n";
$mail_header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
$mail_header .= "This is a multi-part message in MIME format.\n";
// Mail-Text:
$mail_header .= "--".$boundary;
$mail_header .= "\nContent-Type: text/plain";
$mail_header .= "\nContent-Transfer-Encoding: 8bit";
//$mail_header .= "\n\n".$text ;
$mail_header .= "Datum genomen:" . $date . "\n"
. "plaats:" . $place . "\n\n"
. "Opmerkingen:" . $text ;
// Attachment 1:
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: "
.$_FILES['probe']['type']."; name=\""
.$_FILES['probe']['name']."\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\""
.$_FILES['probe']['name']."\"";
$mail_header .= "\n\n".$datei_content;
// Attachment 2:
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: "
.$_FILES['probe2']['type']."; name=\""
.$_FILES['probe2']['name']."\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\""
.$_FILES['probe2']['name']."\"";
$mail_header .= "\n\n".$datej_content;
// End:
$mail_header .= "\n--".$boundary."--";
// Sende E-Mail und gebe Fehler bzw. Bestaetigung aus
if (@mail($mailto,$mail_subject,"",$mail_header)) $sent = true;
else $errors[] = "no connection to the mailserver - please try again later";
}
// no attachment, normal E-mail:
else {
$mail_header = "From: ".$mail_name." <".$mail_email.">\n";
$mail_header .= "X-Sender-IP: $ip\n";
$mail_header .= "Content-Type: text/plain";
if (@mail($mailto,$mail_subject, $text, $date, $mail_header)) $sent = true;
else $errors[] = "no connection to the mailserver - please try again later";
}
}
if (empty($sent)){
?>
<form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>"
enctype="multipart/form-data">
<table width="80%" border="0">
<tr>
<!-- Naamveld -->
<td width="25%">Naam & Voornaam lid:</td>
<td width="75%"><input name="name" value="<?php
if (isset($name)) echo htmlentities(stripslashes($name));
else echo ""; ?>" size="25" /> </td>
</tr>
<tr>
<!-- Datum veld -->
<td>Datum genomen: </td>
<td><input name="date" value="<?php
if (isset($date)) echo htmlentities(stripslashes($date));
else echo ""; ?>" size="25" /> </td>
</tr>
<tr>
<!-- Locatie veld -->
<td>Plaats genomen: </td>
<td><input name="place" value="<?php
if (isset($place)) echo htmlentities(stripslashes($place));
else echo ""; ?>" size="25" /> </td>
</tr>
<tr>
<!-- Opmerkingen veld -->
<td>Opmerkingen:</td>
<td>
<div align="left">
<textarea name="text" cols="25" rows="7">
<?php
if (isset($text)) echo htmlentities(stripslashes($text));
else echo ""; ?>
</textarea>
</div></td>
</tr>
<tr>
<td>Bijlagen: </td>
<td><input type="file" name="probe" value="<?php
if (isset($_POST['probe']))
echo htmlentities(stripslashes($_POST['probe']));
else echo ""; ?>" size="16" /> </td>
</tr>
<tr>
<td> </td>
<td><input type="file" name="probe2" value="<?php
if (isset($_POST['probe2']))
echo htmlentities(stripslashes($_POST['probe2']));
else echo ""; ?>" size="16" />
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="form_submitted" value="OK - Verzenden" /> </td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
// E-mail adres waar de form naartoe zal worden gestuurd:
$mailto = "[email protected]";
# Maximum grootte van het attachment in bytes:
$max_attach_size = 500000;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Formmailer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
// Actie als op de knop 'verzenden' wordt gedrukt
if (isset($_POST["form_submitted"])){
// zal in de mail toekomen als 'afzender'. Hier naam en voornaam van het lid
$name = $_POST['name'];
//$email = $_POST['email'];
// zal in de mail toekomen als 'onderwerp'
$subject = $_POST['subject'];
// zal in de mail toekomen als 'inhoud'
$date = $_POST['date'];
$place = $_POST['place'];
$text = $_POST['text'];
// weergeven van fouten
unset($errors);
$mail_name=$name;
$mail_subject = "mail vanuit webformulier";
$ip = $_SERVER["REMOTE_ADDR"];
// if attachment, MIME-Mail:
if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != ""){
// read and encode file:
$datei_content = fread(fopen($_FILES['probe']['tmp_name'],"r"),
filesize($_FILES['probe']['tmp_name']));
$datei_content = chunk_split(base64_encode($datei_content),76,"\n");
// Boundary:
$boundary = md5(uniqid(rand()));
// Mail-Header:
$mail_header = "From: ".$mail_name." <".$mail_email.">\n";
$mail_header .= "X-Sender-IP: ".$ip."\n";
$mail_header .= "MIME-Version: 1.0\n";
$mail_header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
$mail_header .= "This is a multi-part message in MIME format.\n";
// Mail-Text:
$mail_header .= "--".$boundary;
$mail_header .= "\nContent-Type: text/plain";
$mail_header .= "\nContent-Transfer-Encoding: 8bit";
//$mail_header .= "\n\n".$text ;
$mail_header .= "Datum genomen:" . $date . "\n"
. "plaats:" . $place . "\n\n"
. "Opmerkingen:" . $text ;
// Attachment 1:
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: "
.$_FILES['probe']['type']."; name=\""
.$_FILES['probe']['name']."\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\""
.$_FILES['probe']['name']."\"";
$mail_header .= "\n\n".$datei_content;
// Attachment 2:
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: "
.$_FILES['probe2']['type']."; name=\""
.$_FILES['probe2']['name']."\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\""
.$_FILES['probe2']['name']."\"";
$mail_header .= "\n\n".$datej_content;
// End:
$mail_header .= "\n--".$boundary."--";
// Sende E-Mail und gebe Fehler bzw. Bestaetigung aus
if (@mail($mailto,$mail_subject,"",$mail_header)) $sent = true;
else $errors[] = "no connection to the mailserver - please try again later";
}
// no attachment, normal E-mail:
else {
$mail_header = "From: ".$mail_name." <".$mail_email.">\n";
$mail_header .= "X-Sender-IP: $ip\n";
$mail_header .= "Content-Type: text/plain";
if (@mail($mailto,$mail_subject, $text, $date, $mail_header)) $sent = true;
else $errors[] = "no connection to the mailserver - please try again later";
}
}
if (empty($sent)){
?>
<form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>"
enctype="multipart/form-data">
<table width="80%" border="0">
<tr>
<!-- Naamveld -->
<td width="25%">Naam & Voornaam lid:</td>
<td width="75%"><input name="name" value="<?php
if (isset($name)) echo htmlentities(stripslashes($name));
else echo ""; ?>" size="25" /> </td>
</tr>
<tr>
<!-- Datum veld -->
<td>Datum genomen: </td>
<td><input name="date" value="<?php
if (isset($date)) echo htmlentities(stripslashes($date));
else echo ""; ?>" size="25" /> </td>
</tr>
<tr>
<!-- Locatie veld -->
<td>Plaats genomen: </td>
<td><input name="place" value="<?php
if (isset($place)) echo htmlentities(stripslashes($place));
else echo ""; ?>" size="25" /> </td>
</tr>
<tr>
<!-- Opmerkingen veld -->
<td>Opmerkingen:</td>
<td>
<div align="left">
<textarea name="text" cols="25" rows="7">
<?php
if (isset($text)) echo htmlentities(stripslashes($text));
else echo ""; ?>
</textarea>
</div></td>
</tr>
<tr>
<td>Bijlagen: </td>
<td><input type="file" name="probe" value="<?php
if (isset($_POST['probe']))
echo htmlentities(stripslashes($_POST['probe']));
else echo ""; ?>" size="16" /> </td>
</tr>
<tr>
<td> </td>
<td><input type="file" name="probe2" value="<?php
if (isset($_POST['probe2']))
echo htmlentities(stripslashes($_POST['probe2']));
else echo ""; ?>" size="16" />
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="form_submitted" value="OK - Verzenden" /> </td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
Veel plezier!
Ik zit met hetzelfde probleem en hetzelfde script.
bvd,
Chris