Help..
I am trying to design a page where i can send form data and attachments to an email address. This is done through a html and php file to begin with just to test and with validation later.
I will paste the code below of the html and php file. The problem is that when submitting data along with attachment i am receiving the following errors. I can not understand why?
Warning: fopen(house.jpg): failed to open stream: No such file or directory in /home/prideofp/www/www/sendmixed.php on line 6
Warning: fread(): supplied argument is not a valid stream resource in /home/prideofp/www/www/sendmixed.php on line 9
Warning: fclose(): supplied argument is not a valid stream resource in /home/prideofp/www/www/sendmixed.php on line 45
The html file code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Attached Form</title>
</head>
<body>
<form action="sendmixed.php" 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" value="Send Form" />
</td>
</tr>
</table>
</form>
</body>
</html>
The php file code
<?php
#variables passed are $to,$from,$re,$comments,$att
#open the file
$fp = fopen( $att_name, "r");
#read the file into a variable
$file = fread( $fp, $att_size );
#encode the data for safe transit
#and insert \r\n every 76-characters
$file = chunk_split(base64_encode($file));
#get a random 32 character hexadecimal number
$num = md5(time() );
#define the main headers
$hdr = "From:$from\r\n";
$hdr .="MIME-Version: 1.0\r\n";
$hdr .="Content-Type: multipart/mixed; ";
$hdr .="boundary=$num\r\n";
$hdr .="--$num\r\n"; #start boundary here
#define the message section
$hdr .="Content-Type: text/plain\r\n";
$hdr .="Content-Transfer-Encoding: 8bit\r\n\n";
$hdr .="$comments\r\n";
$hdr .="--$num\n"; #start boundary here
#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--"; #final boundary here
#send the email now...
mail( $to, $re, "", $hdr);
#close the file
fclose($file);
?>
<html><head><title>Send Mixed Received</title></head>
<body>
<h3>Thanks For your Comments</h3>
Message Received from <?php echo($from); ?><br>
Reply to <?php echo($from); ?>
</body></html>
Can anybody help please....
Thanks
php-learner