Ik heb een emailformulier waar een bijlage meegestuurd kan worden.
Het bestand word echter niet goed gelezen. Hetzelfde script gebruik ik ook bij een andere hoster en daar werkt het wel.
Weet iemand hoe dit kan?
Wanneer ik dit script test, krijg ik als bijlage een text bestand met het volgende daarin:
Content-Type: application/octet-stream; name=logo.gif
Content-Transfer-Encoding: base64
Content-disposition: attachment
R0lGODlhNgEyALMAAKwAHv3...
/8CgcEgsGo/IpHLJbDqf0Kh0Sq...
DQSCBA0OBQgBe4ptAQsECp...
Aq2kBAILCMAIBQahCgK3yFcL...enz.
Het bestand word echter niet goed gelezen. Hetzelfde script gebruik ik ook bij een andere hoster en daar werkt het wel.
Weet iemand hoe dit kan?
Wanneer ik dit script test, krijg ik als bijlage een text bestand met het volgende daarin:
Content-Type: application/octet-stream; name=logo.gif
Content-Transfer-Encoding: base64
Content-disposition: attachment
R0lGODlhNgEyALMAAKwAHv3...
/8CgcEgsGo/IpHLJbDqf0Kh0Sq...
DQSCBA0OBQgBe4ptAQsECp...
Aq2kBAILCMAIBQahCgK3yFcL...enz.
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
| //geneer boundary DEFINE('bound',md5(uniqid(time()))); //check request method if($_SERVER['REQUEST_METHOD'] == 'POST'){ //if file upload send with email as mixed if(!empty($_FILES['file']['name'])) { //check filesize if($_FILES['file']['size'] < 1024*50) { $headers = "From: $email\r\n"; $headers .= "MIME-Version: 1.0\r\n"; //email bestaat uit meerdere bestanden dus vertel wat de scheidings teken is en dat het een multipart is $headers .= "Content-Type: multipart/mixed; boundary=\"".bound."\"\r\n"; //we zenden een attachment mee $headers .= "Content-Disposition: attachment\r\n"; //readfile $fp = fopen($_FILES['file']['tmp_name'],'r'); $bestand = fread($fp,$_FILES['file']['size']); fclose($fp); //create body //generenen een body. Dit is een multi part gezeik $body.= "This is a multi-part message in MIME format.\r\n"; $body.= "\r\n"; //boundary $body.= "--".bound."\r\n"; //content type + charater set (iso in dit geval) $body.= "Content-Type: text/plain; charset=iso-8859-1\r\n"; //codering (7 bit) $body.= "Content-Transfer-Encoding: 7bit\r\n"; $body.= "\r\n"; //het bericht $body .="Betreft: Bericht via de website\r\n"; $body .="Naam: $naam\n"; $body .="Adres: $adres\n"; $body .="Postcode: $postcode\n"; $body .="Woonplaats: $plaats\n"; $body .="Email: $email\n"; $body .="Tel: $telefoon\n"; $body .="Opmerking: $opmerking\n"; //boundary $body.= "--".bound."\r\n"; $body .= "Content-Type: application/octet-stream; name=".$_FILES['file']['name']."\r\n"; //codering $body .= "Content-Transfer-Encoding: base64\r\n"; //als bijlage toegevoegd $body.= "Content-disposition: attachment\r\n"; $body .= "\n"; //de inhoud van het bestand $body .= chunk_split(base64_encode($bestand )) . "\r\n"; mail($ontvanger2,$onderwerp2,$body,$headers); echo "Bedankt voor uw email.<br />Wij nemen zo spoedig mogelijk contact met u op."; } else { echo 'De bestandsgrootte van uw pbijlage is te groot.<br />Probeert u het nogmaals met een kleiner bestandsformaat.'; } } |
[ Voor 4% gewijzigd door RobIII op 13-02-2007 01:04 . Reden: even wat layout vern**kende crap weggehaald ;) ]