Current location: Hot Scripts Forums » Programming Languages » PHP » Sending form data + attatchments in email


Sending form data + attatchments in email

Reply
  #1 (permalink)  
Old 02-12-04, 02:31 PM
php-learner php-learner is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Sending form data + attatchments in email

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-14-04, 01:14 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

Quote:
Warning: fopen(house.jpg): failed to open stream: No such file or directory in /home/prideofp/www/www/sendmixed.php on line 6
Whenever you get this error, you should check whether the requested file (i.e. 'house.jpg' in this case) really exists. Do you have the file named "house.jpg" in the same directory as the script "sendmixed.php"? If you have it in a subdir like img/, then you have to specify that, too. HTH.
__________________
Blavv =|
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-14-04, 01:18 AM
tskweb tskweb is offline
Newbie Coder
 
Join Date: Jul 2003
Location: Plano, TX
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Try this!!!

http://www.phpclasses.org/browse/file/2446.html

Here is agood Class to do what you are doing.

I haven't used it but reading it seemd pretty straight forward.
__________________
Scott
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 04:06 AM
Collecting html form data and sending it to a sql table crobinson ASP 3 01-04-04 10:16 PM
Preventing email form abuse LunarOrbit Perl 3 10-04-03 10:55 PM
send email when sending form (asp) bmatth1 Script Requests 0 09-30-03 06:52 AM


All times are GMT -5. The time now is 02:01 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.