in mailform met bijlage een 2de bijlage uit site laten versturen
MAAR ik zou er nog enkele extra's aan willen toevoegen zodoende dat ik het kan gebruiken waarvoor ik het nodig heb.
Voor de website van mijn ouders zou ik een mailform moeten maken waar de klanten een foto of andere afbeelding via formulier kunnen meeposten. (dit heb ik dus al) Maar ik zou het ook tof vinden als de klanten ook nog een 2de bestand kunnen posten dmv dit bestand te selecteren op de website (dus eigenlijk een soort van radiobutton maar dan op aparte pagina en met foto's ernaast ... Dat ze van deze foto's enkel de naam doorzenden kan ook ...)
Het is voor onze klanten die foto ballonnen willen laten maken een foto (1ste bestand) kunnen verzenden en dan ook kunnen kiezen welke kader (2de bestand) ze om de foto willen hebben.
Het mailform zoals ik het nu heb ben ik aan het testen op www.jeugdensemble.be/test.php
// Hier mijn code tot nu toe //
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
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
<?php
// Your e-mail adress:
$mailto = "[email protected]";
# Maximum size of attachment in bytes:
$max_attach_size = 5000000;
/*if (empty($_POST['form_submitted']))
{
?></font><p><font color="#FFFFFF">Please fill out the form:</font></p>
<font color="#FFFFFF"><?php
}
*/
if (isset($_POST["form_submitted"]))
{
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$text = $_POST['text'];
unset($errors);
if ($email != "" and !preg_match("/^[^@]+@.+\.\D{2,5}$/", $email)) $errors[] = "e-mail address lijkt incorrect";
if ($text == "") $errors[] = "Geen bericht geplaatst";
if ($_FILES['probe']['size'] > $max_attach_size) $errors[] = "Bijlage is te groot(".number_format($_FILES['probe']['size']/1000,0,",","")." KB) - maximum size: ".number_format($max_attach_size/1000,0,",","")." KB";
if (empty($errors))
{
$text = stripslashes($text);
$subject = stripslashes($subject);
if ($name != "") $mail_name=$name; else $mail_name="Unknown";
if ($subject != "") $mail_subject = $subject; else $mail_subject = "No subject";
if ($email != "") $mail_email = $email; else $mail_email = "[email protected]";
$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;
// Attachment:
$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;
// 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,$mail_header)) $sent = true; else $errors[] = "no connection to the mailserver - please try again later";
}
// copy to sender:
if (isset($sent) && isset($email) && $email != "" && isset($_POST['copy']))
{
if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "") $copy_mail_text = "Copy of the e-mail:\n\n".$text."\n\nAttachment: ".$_FILES['probe']['name']; else $copy_mail_text = "Copy of the e-mail:\n\n".$text;
$header= "From: ".$mailto."\n";
$header .= "X-Sender-IP: ".$ip."\n";
$header .= "Content-Type: text/plain";
@mail($email, $mail_subject, $copy_mail_text, $header);
}
}
}
if (empty($sent))
{
if(isset($errors))
{
?><p class="caution">Error:</p><ul>
<?php foreach($errors as $f) { ?><li>
<?php echo $f; ?></li><?php } ?></ul>
<br /><?php
}
?><form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"><div>
<p> Naam:<br />
<input name="name" value="<?php if (isset($name)) echo htmlentities(stripslashes($name)); else echo ""; ?>" size="25" />
<br />
E-mail:<br />
<input name="email" value="<?php if (isset($email)) echo htmlentities(stripslashes($email)); else echo ""; ?>" size="25" />
<br />
Onderwerp:<br />
<input name="subject" value="<?php if (isset($subject)) echo htmlentities(stripslashes($subject)); else echo ""; ?>" size="25" />
<br />
Bericht:<br />
<textarea name="text" cols="25" rows="7" ><?php if (isset($text)) echo htmlentities(stripslashes($text)); else echo ""; ?>
</textarea>
<br />
Bijlagen:<br />
<input type="file" name="probe" value="<?php if (isset($_POST['probe'])) echo htmlentities(stripslashes($_POST['probe'])); else echo ""; ?>" size="16" />
</p>
</p>
<p><input type="checkbox" name="copy" value="true" />
Kopietje naar jezelf sturen?
<input type="submit" name="form_submitted" value="OK - Verzenden" />
</p>
</div>
</form><?php
}
else
{
if (empty($email)) { ?></font></font><font color="#FFFFFF"> </font>
<p><b>Bedankt!</b><br />
Je mail is verzonden alleen kan ik je niet terug mailen omdat je geen e-mail
adres hebt ingevuld! </font></font></p>
<?php }
else { ?>
<p><b>Bedankt!</b><br />
Je bericht is met succes verzonden ik zal zo spoedig mogelijk terug mailen.
</p>
<?php }
}
?>
// Your e-mail adress:
$mailto = "[email protected]";
# Maximum size of attachment in bytes:
$max_attach_size = 5000000;
/*if (empty($_POST['form_submitted']))
{
?></font><p><font color="#FFFFFF">Please fill out the form:</font></p>
<font color="#FFFFFF"><?php
}
*/
if (isset($_POST["form_submitted"]))
{
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$text = $_POST['text'];
unset($errors);
if ($email != "" and !preg_match("/^[^@]+@.+\.\D{2,5}$/", $email)) $errors[] = "e-mail address lijkt incorrect";
if ($text == "") $errors[] = "Geen bericht geplaatst";
if ($_FILES['probe']['size'] > $max_attach_size) $errors[] = "Bijlage is te groot(".number_format($_FILES['probe']['size']/1000,0,",","")." KB) - maximum size: ".number_format($max_attach_size/1000,0,",","")." KB";
if (empty($errors))
{
$text = stripslashes($text);
$subject = stripslashes($subject);
if ($name != "") $mail_name=$name; else $mail_name="Unknown";
if ($subject != "") $mail_subject = $subject; else $mail_subject = "No subject";
if ($email != "") $mail_email = $email; else $mail_email = "[email protected]";
$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;
// Attachment:
$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;
// 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,$mail_header)) $sent = true; else $errors[] = "no connection to the mailserver - please try again later";
}
// copy to sender:
if (isset($sent) && isset($email) && $email != "" && isset($_POST['copy']))
{
if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "") $copy_mail_text = "Copy of the e-mail:\n\n".$text."\n\nAttachment: ".$_FILES['probe']['name']; else $copy_mail_text = "Copy of the e-mail:\n\n".$text;
$header= "From: ".$mailto."\n";
$header .= "X-Sender-IP: ".$ip."\n";
$header .= "Content-Type: text/plain";
@mail($email, $mail_subject, $copy_mail_text, $header);
}
}
}
if (empty($sent))
{
if(isset($errors))
{
?><p class="caution">Error:</p><ul>
<?php foreach($errors as $f) { ?><li>
<?php echo $f; ?></li><?php } ?></ul>
<br /><?php
}
?><form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"><div>
<p> Naam:<br />
<input name="name" value="<?php if (isset($name)) echo htmlentities(stripslashes($name)); else echo ""; ?>" size="25" />
<br />
E-mail:<br />
<input name="email" value="<?php if (isset($email)) echo htmlentities(stripslashes($email)); else echo ""; ?>" size="25" />
<br />
Onderwerp:<br />
<input name="subject" value="<?php if (isset($subject)) echo htmlentities(stripslashes($subject)); else echo ""; ?>" size="25" />
<br />
Bericht:<br />
<textarea name="text" cols="25" rows="7" ><?php if (isset($text)) echo htmlentities(stripslashes($text)); else echo ""; ?>
</textarea>
<br />
Bijlagen:<br />
<input type="file" name="probe" value="<?php if (isset($_POST['probe'])) echo htmlentities(stripslashes($_POST['probe'])); else echo ""; ?>" size="16" />
</p>
</p>
<p><input type="checkbox" name="copy" value="true" />
Kopietje naar jezelf sturen?
<input type="submit" name="form_submitted" value="OK - Verzenden" />
</p>
</div>
</form><?php
}
else
{
if (empty($email)) { ?></font></font><font color="#FFFFFF"> </font>
<p><b>Bedankt!</b><br />
Je mail is verzonden alleen kan ik je niet terug mailen omdat je geen e-mail
adres hebt ingevuld! </font></font></p>
<?php }
else { ?>
<p><b>Bedankt!</b><br />
Je bericht is met succes verzonden ik zal zo spoedig mogelijk terug mailen.
</p>
<?php }
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Jan Augustijnen
Gewijzigd op 01/01/1970 01:00:00 door jan Augustijnen
Is het je ooit gelukt een 2e attachment bij dit script te krijgen? ik zoek exact hetzelfde..