Hello,
The following is a script I'm trying to use to send an attachment from a web form.
When I run the script I get two error messages as follows.
Warning: fread(): supplied argument is not a valid stream resource in /home/justamo/www/aaa_2008/web/sendmixed.php on line 19
Warning: fclose(): supplied argument is not a valid stream resource in /home/justamo/www/aaa_2008/web/sendmixed.php on line 20
The script is listed below, other info is file permissions are set to 777.
Any advice on how to get this working would be good. Emails are getting through but without attachments arriving.
Thanks in advance.
<?php
$to = 'me@mydomain.com';
$from = 'noreply@mydomain.com';
$name = $_POST['name'];
$phone = $_POST['phone'];
$att = $_FILES['att'];
$att_path = $_FILES['att']['tmp_name'];
$att_name = $_FILES['att']['name'];
$att_size = $_FILES['att']['size'];
$att_type = $_FILES['att']['type'];
#open, read then close the file
$fp = fopen( $att_path, 'r');
$file = fread( $fp, $att_size );
fclose( $fp );
#create a boundary string
$num = md5(time());
$str = "==Multipart_Boundary_x{$num}x";
#encode the data for safe transit
#and intersperse 76-character chunks with \r\n
$file = chunk_split(base64_encode($file));
#define header
$hdr = "From: $from\n";
$hdr .= "MIME-Version: 1.0\n";
$hdr .= "Content-Type: multipart/mixed;\n ";
$hdr .= "boundary=\"{$str}\"";
#define message
$msg = "This is a multi-part message in MIME format\n\n";
$msg .= "--{$str}\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 8bit\n\n";
$msg .= "$name\n\n";
$msg .= "$phone\n\n";
$msg .= "--{$str}\n";
#define the non-text attachment
$msg .= "Content-Type: {$att_type};\n";
$msg .= "name=\"{$att_name}\"\n";
$msg .= "Content-Disposition: attachment;\n";
$msg .= "filename=\"{$att_name}\"\n";
$msg .= "Content-Transfer-Encoding: base64\n\n";
$msg .= "$file\n\n";
$msg .= "--{$str}";
$re = 'Brief submission via website';
#send the email now...
$ok = mail( $to, $re, $msg, $hdr);
if($ok) echo "OK";
?>