I have a main form for inputing the (to/from/mesg/file) with the following code:-
<html>
<body>
<table>
<tr>
<td>To:</td>
<td><input type="text" name="to" size="50"
value="pras_sandilya@rediffmail.com"></td>
</tr>
<tr>
<td>From:</td>
<td><input type="text" name="from" size="50"></td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" name="subject"
size="50"></td>
</tr>
<tr>
<td>Message:</td>
<td>
<textarea cols="60" rows="5" name="message"
>Enter Your queries here</textarea>
</td>
</tr>
<td>
<form
action="http://www.urovisionhospital.com/ematt.php"
id="upload" ENCTYPE="multipart/form-data"
method="post">
Browse File<input type="file" id="abc" name="abc">
<input type="submit" name="upload" value="SEND
MAIL">
</form>
<input type="reset" value="Reset the form">
</td>
</table>
</body>
</html>
then I use theabove form to send the email with attachment: The next code first uploads to tmp dir on server and then sends the mail from the server.:-
<?php
$message ="file uploaded";
$temp_name = $_FILES['abc']['tmp_name'];
$file_name = $_FILES['abc']['name'];
$file_type = $_FILES['abc']['type'];
$file_size = $_FILES['abc']['size'];
$result = $_FILES['abc']['error'];
$upDir="/home/urovisio/tmp/";
$upload_dir=$upDir . $temp_name;
//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
//File Size Check
else if ( $file_size > 500000) {
$message = "The file size is over 500K.";
return $message;
}
//File Type Check
else if ( $file_type == "text/plain" ) {
$message = "Sorry, You cannot upload any script
file" ;
return $message;
}
if(move_uploaded_file($_FILES['abc']['tmp_name'],$u
pload_dir)){
print $message;
}
?>
<?php
$to = $_POST["to"];
$from = $_POST["from"];
$subject = $_POST["Subject"];
$fileatt = $upload_dir;
$fileatttype = "application/octet-stream";
$start= strrpos($fileatt, '/') == -1 ?
strrpos($fileatt, '//') : strrpos($fileatt, '/')+1;
$fileatt_name = substr($fileatt, $start,
strlen($fileatt)); // Filename that will be used
for the file as the attachment
$headers = "From: $from";
?>
<?php
$file = fopen( $fileatt, 'rb' );
$data = fread( $file, filesize( $fileatt )
);
fclose( $file );
?>
<?php
$semi_rand = md5( time() );
$mime_boundary =
"==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type:
multipart/mixed;\n" .
"
boundary=\"{$mime_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";
$data = chunk_split( base64_encode( $data )
);
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n"
.
" name=\"{$fileattname}\"\n" .
"Content-Disposition:
attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding:
base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
?>
<?php
if( mail( $to, $subject, $message, $headers
) ) {
echo "<p>The email was sent.</p>";
}
else {
echo "<p>There was an error sending the
mail.</p>";
}
?>
I get the error msg:move file upload /failed to open stream.
Kindly help in the coding.
regards,
P.Sandilya