mailen met attachment met iis6.0 en php 5.1.4
Ik heb meerdere script geprobeerd, alles werkt, totdat ik attachments selecteer vanuit een form en die dan mee wil sturen. melding is dan:
Warning: fread()supplied argument is not a valid stream resource in ... line 37
Warning: fclose()supplied argument is not a valid stream resource in ... line 81.
De bijbehorende code staat hieronder:
===========================
<form action="" method="post"
enctype="multipart/form-data">
<table>
<tr>
<td>To:</td>
<td><input type="text" name="to" size="40"/></td>
</tr>
<tr>
<td>From:</td>
<td><input type="text" name="from" size="40" /></td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" name="re" size="40" /></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea cols="30" rows="5" name="comments"></textarea></td>
</tr>
<tr>
<td>Attachment:</td>
<td><input type="file" name="att" size="26" /></td>
</tr>
<td colspan="2"><input type="submit" name="submit" value="Send Form" /></td>
</tr>
</table>
</form>
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
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
<?php
}else{
extract($_POST);
$fp = fopen( $att, "r");
$file = fread( $fp, $att_size );
/*
Encode The Data For Transition using base64_encode();
And get a 32-character hexadecimal number
*/
$file = chunk_split(base64_encode($file));
$num = md5( time() );
/*
Define the main message headers
*/
$hdr = "From:".$_REQUEST['from']."\r\n";
$hdr .= "MIME-Version: 1.0\r\n";
$hdr .= "Content-Type: multipart/mixed; ";
$hdr .= "boundary=".$num."\r\n";
$hdr .= "--$num\r\n";
/*
Define message section
*/
$hdr .= "Content-Type: text/plain\r\n";
$hdr .= "Content-Transfer-Encoding: 8bit\r\n\n";
$hdr .= "".$_REQUEST['comments']."\r\n";
$hdr .= "--".$num."\n";
/*
Define the attachment section
*/
$hdr .= "Content-Type:". $att_type." ";
$hdr .= "name=\"".$att_name."\"r\n";
$hdr .= "Content-Transfer-Encoding: base64\r\n";
$hdr .= "Content-Disposition: attachment; ";
$hdr .= "filename=\"".$att_name."\"\r\n\n";
$hdr .= "".$file."\r\n";
$hdr .= "--".$num."--";
/*
Send the email
*/
mail( $_REQUEST['to'], $_REQUEST['re'], $_REQUEST['comments'], $hdr);
/*
Close the attachment
*/
fclose( $fp );
echo "Mail sent...";
}
?>
}else{
extract($_POST);
$fp = fopen( $att, "r");
$file = fread( $fp, $att_size );
/*
Encode The Data For Transition using base64_encode();
And get a 32-character hexadecimal number
*/
$file = chunk_split(base64_encode($file));
$num = md5( time() );
/*
Define the main message headers
*/
$hdr = "From:".$_REQUEST['from']."\r\n";
$hdr .= "MIME-Version: 1.0\r\n";
$hdr .= "Content-Type: multipart/mixed; ";
$hdr .= "boundary=".$num."\r\n";
$hdr .= "--$num\r\n";
/*
Define message section
*/
$hdr .= "Content-Type: text/plain\r\n";
$hdr .= "Content-Transfer-Encoding: 8bit\r\n\n";
$hdr .= "".$_REQUEST['comments']."\r\n";
$hdr .= "--".$num."\n";
/*
Define the attachment section
*/
$hdr .= "Content-Type:". $att_type." ";
$hdr .= "name=\"".$att_name."\"r\n";
$hdr .= "Content-Transfer-Encoding: base64\r\n";
$hdr .= "Content-Disposition: attachment; ";
$hdr .= "filename=\"".$att_name."\"\r\n\n";
$hdr .= "".$file."\r\n";
$hdr .= "--".$num."--";
/*
Send the email
*/
mail( $_REQUEST['to'], $_REQUEST['re'], $_REQUEST['comments'], $hdr);
/*
Close the attachment
*/
fclose( $fp );
echo "Mail sent...";
}
?>
==========================
Deze code ook getest op een andere server met apache en php4.4.1 en dat gaat gewoon goed.
Ik denk dat het iets te maken heeft met iis6.0 en de php versie. Vorige server was server 2000 en een php 4 versie en dat ging geweldig.
Voor alle duidelijkheid, het ligt denk ik niet aan het script omdat deze wel werkt met php4. Andere uitgebreide mailingscripts werken ook niet met mijn server en php5 combinatie.
Wie heeft een suggestie waar ik de oplossing zou moeten zoeken.
Gewijzigd op 01/01/1970 01:00:00 door Jaap Eijk
Er zijn nog geen reacties op dit bericht.