Mailfunctie 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
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
<?php
// array with filenames to be sent as attachment
$docx='http://zwatje.site40.net/Inschrijvingen/PDF/'.$_GET['voornaam'].'_'.$_GET['achternaam'].' ('.$_GET['lifenr'].')-2012_2013.docx';
$pdf='http://zwatje.site40.net/Inschrijvingen/PDF/'.$_GET['voornaam'].'_'.$_GET['achternaam'].' ('.$_GET['lifenr'].')-2012_2013.pdf';
$files = array( "$docx", "$pdf");
// email fields: to, from, subject, and so on
$to = "[email protected]";
$from = "ZWAT Inschrijvingsfiches <[email protected]>";
$subject ='[ZWAT] Herinschrijvingsfiches '.$_GET[voornaam].' '.$_GET[achternaam];
$message = "Beste secretaris,
in bijlage vindt u meer informatie omtrent een nieuwe inschrijving voor komend seizoen.
Vriendelijke groeten,
Olivier Peeters
Beheerder inschrijvingsfiche";
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],"rb");
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
// send
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Je herinschrijving is goed verzonden naar de secretaris</p>";
} else {
echo "<p>Er traden fouten op bij het verzenden van de inschrijvingsinformatie. Neem contact op met de webmaster!</p>";
}
?>
// array with filenames to be sent as attachment
$docx='http://zwatje.site40.net/Inschrijvingen/PDF/'.$_GET['voornaam'].'_'.$_GET['achternaam'].' ('.$_GET['lifenr'].')-2012_2013.docx';
$pdf='http://zwatje.site40.net/Inschrijvingen/PDF/'.$_GET['voornaam'].'_'.$_GET['achternaam'].' ('.$_GET['lifenr'].')-2012_2013.pdf';
$files = array( "$docx", "$pdf");
// email fields: to, from, subject, and so on
$to = "[email protected]";
$from = "ZWAT Inschrijvingsfiches <[email protected]>";
$subject ='[ZWAT] Herinschrijvingsfiches '.$_GET[voornaam].' '.$_GET[achternaam];
$message = "Beste secretaris,
in bijlage vindt u meer informatie omtrent een nieuwe inschrijving voor komend seizoen.
Vriendelijke groeten,
Olivier Peeters
Beheerder inschrijvingsfiche";
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],"rb");
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
// send
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Je herinschrijving is goed verzonden naar de secretaris</p>";
} else {
echo "<p>Er traden fouten op bij het verzenden van de inschrijvingsinformatie. Neem contact op met de webmaster!</p>";
}
?>
Hallo allen,
eerst het script dan de uitleg :*) Bovenstaand script heb ik gekopieerd en aangepast. Als ik dit toepas krijg ik volgende meldingen:
PHP Error Message
Notice: Use of undefined constant voornaam - assumed 'voornaam' in /home/a5852590/public_html/Inschrijvingen/PDF/documentenmailen.php on line 13
Free Web Hosting
PHP Error Message
Notice: Use of undefined constant achternaam - assumed 'achternaam' in /home/a5852590/public_html/Inschrijvingen/PDF/documentenmailen.php on line 13
Free Web Hosting
PHP Error Message
Warning: filesize() [function.filesize]: stat failed for http://zwatje.site40.net/Inschrijvingen/PDF/Olivier_Peeters (55555555)-2012_2013.docx in /home/a5852590/public_html/Inschrijvingen/PDF/documentenmailen.php on line 36
Free Web Hosting
PHP Error Message
Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/a5852590/public_html/Inschrijvingen/PDF/documentenmailen.php on line 36
Free Web Hosting
PHP Error Message
Warning: filesize() [function.filesize]: stat failed for http://zwatje.site40.net/Inschrijvingen/PDF/Olivier_Peeters (55555555)-2012_2013.pdf in /home/a5852590/public_html/Inschrijvingen/PDF/documentenmailen.php on line 36
Free Web Hosting
PHP Error Message
Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/a5852590/public_html/Inschrijvingen/PDF/documentenmailen.php on line 36
Free Web Hosting
Nochtans bestaat mijn document wel degelijk op mijn server. Ik krijg mijn mail dus verzonden, maar wel met een leeg doc-document en een onleesbaar pdf-document.
Kent iemand de oplossing?
Ikzelf heb al zitten proberen, maar zie het niet (meer).....
Ik dank u voor uw medewerking ;-)
Groeten,
Olivier
Die error zegt toch genoeg?
Groeten,
Olivier
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?php
// hier mis je wat quotes :)
$subject ='[ZWAT] Herinschrijvingsfiches '.$_GET['voornaam'].' '.$_GET['achternaam'];
// die @ daar weg dat onderdrukt alleen maar foutmeldingen..
$ok = mail($to, $subject, $message, $headers);
?>
// hier mis je wat quotes :)
$subject ='[ZWAT] Herinschrijvingsfiches '.$_GET['voornaam'].' '.$_GET['achternaam'];
// die @ daar weg dat onderdrukt alleen maar foutmeldingen..
$ok = mail($to, $subject, $message, $headers);
?>
Ik zal de quotes aanpassen, worden die fread problemen dan ook opgelost enzo?
Groeten
Wees consequent in gebruik van " en '
Zijn de mailheaders compleet? Gebruik liever phpmailer of swiftmailer --> hoef je zelf niet alles te 'ontdekken'.
Verder krijg je genoeg foutmeldingen; probeer die eerst maar allemaal op te lossen. En dan niet met @ om fouten te onderdrukken.