mailscript: Inhoud van bijlage is gecodeerd bij het openen
Ik heb eindelijk het voor elkaar dat er een bijlage mee gestuurd kan worden via een formulier. Nu het enige probleem is dat de inhoud van de bijlage (in dit geval .doc) wordt ge-encodeerd ofzo.
ik heb het volgende script dat eerst het bestand upload:
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
$uploaddir = $_SERVER['DOCUMENT_ROOT']."/tmp/";
move_uploaded_file($_FILES['attachment']['tmp_name'], $uploaddir.basename($_FILES['attachment']['name']));
$attach['name'] = $_FILES['attachment']['name'];
$attach['path'] = $uploaddir.basename($_FILES['attachment']['name']);
$attachment_name = $_FILES['attachment']['name'];
$attachment_type = $_FILES['attachment']['type'];
$attachment_size = $_FILES['attachment']['size'];
$attachment_path = $uploaddir.basename($_FILES['attachment']['name']);
move_uploaded_file($_FILES['attachment']['tmp_name'], $uploaddir.basename($_FILES['attachment']['name']));
$attach['name'] = $_FILES['attachment']['name'];
$attach['path'] = $uploaddir.basename($_FILES['attachment']['name']);
$attachment_name = $_FILES['attachment']['name'];
$attachment_type = $_FILES['attachment']['type'];
$attachment_size = $_FILES['attachment']['size'];
$attachment_path = $uploaddir.basename($_FILES['attachment']['name']);
Nu het gedeelte wat het bestand opent en encodeert:
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
if ($attachment_name) {
if ($attachment_size > 0) {
if (!$attachment_type) $attachment_type = "application/unknown";
$content .= "Attached File: ".$attachment_name."\n";
$fp = fopen($attachment_path, "r");
$attachment_chunk = fread($fp, filesize($attachment_path));
$attachment_chunk = base64_encode($attachment_chunk);
$attachment_chunk = chunk_split($attachment_chunk);
}
}
if ($attachment_size > 0) {
if (!$attachment_type) $attachment_type = "application/unknown";
$content .= "Attached File: ".$attachment_name."\n";
$fp = fopen($attachment_path, "r");
$attachment_chunk = fread($fp, filesize($attachment_path));
$attachment_chunk = base64_encode($attachment_chunk);
$attachment_chunk = chunk_split($attachment_chunk);
}
}
En uiteindelijk het stuk wat alles doormailt:
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
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
Function mail_it($content, $subject, $email, $recipient) {
global $attachment_chunk, $attachment_name, $attachment_type, $attachment_sent, $bcc;
$ob = "----=_OuterBoundary_000";
$ib = "----=_InnerBoundery_001";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: ".$email."\n";
$headers .= "Reply-To: ".$email."\n";
// if ($bcc) $headers .= "Bcc: ".$bcc."\n";
// $headers .= "X-Priority: 1\n";
// $headers .= "X-Mailer: DT Formmail".VERSION."\n";
$headers .= "Content-Type: multipart/mixed;\n\tboundary=\"".$ob."\"\n";
$message = "This is a multi-part message in MIME format.\n";
$message .= "\n--".$ob."\n";
$message .= "Content-Type: multipart/alternative;\n\tboundary=\"".$ib."\"\n\n";
$message .= "\n--".$ib."\n";
$message .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
//$message .= "Content-Type: text/html;\n\tcharset=\"UTF-8\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n\n";
$message .= $content."\n\n";
$message .= "\n--".$ib."--\n";
if ($attachment_name && !$attachment_sent) {
$message .= "\n--".$ob."\n";
$message .= "Content-Type: $attachment_type;\n\attachment=\"".$attachment_name."\"\n";
$message .= "Content-Disposition: attachment;\n\tfilename=\"".$attachment_name."\"\n\n";
$message .= "Content-Transfer-Encoding: base64\n\n";
$message .= $attachment_chunk;
$message .= "\n\n";
$attachment_sent = 1;
}
$message .= "\n--".$ob."--\n";
mail($recipient, $subject, $message, $headers);
}
global $attachment_chunk, $attachment_name, $attachment_type, $attachment_sent, $bcc;
$ob = "----=_OuterBoundary_000";
$ib = "----=_InnerBoundery_001";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: ".$email."\n";
$headers .= "Reply-To: ".$email."\n";
// if ($bcc) $headers .= "Bcc: ".$bcc."\n";
// $headers .= "X-Priority: 1\n";
// $headers .= "X-Mailer: DT Formmail".VERSION."\n";
$headers .= "Content-Type: multipart/mixed;\n\tboundary=\"".$ob."\"\n";
$message = "This is a multi-part message in MIME format.\n";
$message .= "\n--".$ob."\n";
$message .= "Content-Type: multipart/alternative;\n\tboundary=\"".$ib."\"\n\n";
$message .= "\n--".$ib."\n";
$message .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
//$message .= "Content-Type: text/html;\n\tcharset=\"UTF-8\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n\n";
$message .= $content."\n\n";
$message .= "\n--".$ib."--\n";
if ($attachment_name && !$attachment_sent) {
$message .= "\n--".$ob."\n";
$message .= "Content-Type: $attachment_type;\n\attachment=\"".$attachment_name."\"\n";
$message .= "Content-Disposition: attachment;\n\tfilename=\"".$attachment_name."\"\n\n";
$message .= "Content-Transfer-Encoding: base64\n\n";
$message .= $attachment_chunk;
$message .= "\n\n";
$attachment_sent = 1;
}
$message .= "\n--".$ob."--\n";
mail($recipient, $subject, $message, $headers);
}
De email komt gewoon goed binnen. Er is ook een attachment, maar de attachment zelf lijkt wel geencodeerd. het volgende staat in de .doc die in de bijlage zit:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Content-Transfer-Encoding: base64
0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAANwAAAAAAAAAA
EAAAOQAAAAEAAAD+////AAAAADYAAAD/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////s
pcEAJWATBAAA8BK/AAAAAAAAMAAAAAAABgAA4Q0AAA4AYmpiaiJ4IngAAAAAAAAAAAAAAAAAAAAA
AAAJBBYALiAAAEASAQBAEgEA4QUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAA
AAAAAAD//w8AAAAAAAAAAAD//w8AAAAAAAAAAAAAAAAAAAAAAKQAAAAAAPIHAAAAAAAA8gcAAPIH
AAAAAAAA8gcAAAAAAADyBwAAAAAAAPIHAAAAAAAA8gcAABQAAAAAAAAAAAAAAAYIAAAAAAAADhAA
AAAAAAAOEAAAAAAAAA4QAAAAAAAADhAAACQAAAAyEAAAJAAAAAYIAAAAAAAAURUAADIBAABiEAAA
AAAAAGIQAAAAAAAAYhAAAAAAAABiEAAAAAAAAGIQAAAAAAAAYhAAAAAAAABiEAAAAAAAAGIQAAAA
AAAA0BQAAAIAAADSFAAAAAAAANIUAAAAAAAA0hQAAAAAAADSFAAAAAAAANIUAAAAAAAA0hQAACQA
0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAANwAAAAAAAAAA
EAAAOQAAAAEAAAD+////AAAAADYAAAD/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////s
pcEAJWATBAAA8BK/AAAAAAAAMAAAAAAABgAA4Q0AAA4AYmpiaiJ4IngAAAAAAAAAAAAAAAAAAAAA
AAAJBBYALiAAAEASAQBAEgEA4QUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAA
AAAAAAD//w8AAAAAAAAAAAD//w8AAAAAAAAAAAAAAAAAAAAAAKQAAAAAAPIHAAAAAAAA8gcAAPIH
AAAAAAAA8gcAAAAAAADyBwAAAAAAAPIHAAAAAAAA8gcAABQAAAAAAAAAAAAAAAYIAAAAAAAADhAA
AAAAAAAOEAAAAAAAAA4QAAAAAAAADhAAACQAAAAyEAAAJAAAAAYIAAAAAAAAURUAADIBAABiEAAA
AAAAAGIQAAAAAAAAYhAAAAAAAABiEAAAAAAAAGIQAAAAAAAAYhAAAAAAAABiEAAAAAAAAGIQAAAA
AAAA0BQAAAIAAADSFAAAAAAAANIUAAAAAAAA0hQAAAAAAADSFAAAAAAAANIUAAAAAAAA0hQAACQA
En zo nog 36 pagina's verder.
Weet iemand hoe dit kan en heb je er een oplossing voor?
alvast bedankt!
Gewijzigd op 01/01/1970 01:00:00 door Leon
Gewijzigd op 01/01/1970 01:00:00 door John Doe
Daniel schreef op 23.06.2009 17:31:
zet alsjeblieft tussen tags
Jah sorry, had t tussen [php][/php] tags staan.
Quote:
Nu het enige probleem is dat de inhoud van de bijlage (in dit geval .doc) wordt ge-encodeerd ofzo.
Dat het encoded is vind ik niet zo gek, dat doe je zelf met 'base64_encode()'
Je encode de inhoud van het document dmv fread().
Je kan dat openen in word(2007) via:
Microsoft Office Button->Word Options->Advanced->scroll down to 'general'->check 'Confirm file format conversion on open'. En kies dan tijdens openen voor de goede encoding. (niet getest, dus geen garantie)
Quote:
Dat het encoded is vind ik niet zo gek, dat doe je zelf met 'base64_encode()'
Je encode de inhoud van het document dmv fread().
Je kan dat openen in word(2007) via:
Microsoft Office Button->Word Options->Advanced->scroll down to 'general'->check 'Confirm file format conversion on open'. En kies dan tijdens openen voor de goede encoding. (niet getest, dus geen garantie)
Je encode de inhoud van het document dmv fread().
Je kan dat openen in word(2007) via:
Microsoft Office Button->Word Options->Advanced->scroll down to 'general'->check 'Confirm file format conversion on open'. En kies dan tijdens openen voor de goede encoding. (niet getest, dus geen garantie)
Bedankt voor je reactie.
Het moet wel ge-encodeerd worden. Anders werkt het helemaal niet. Maar ik heb overigens gedaan wat jij zei, maar de juiste codering stond er niet bij helaas... Maar dat zou toch automatisch moeten gebeuren?
Volgens mij moet dat ook automatisch gebeuren ja. Misschien een instelling die niet klopt? Anders heb ik ook geen idee. Er zijn wel losse programma's om zo'n attachment te decoden, maar dat is natuurlijk ook geen nette oplossing.