PHP Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
seriousdamage
Forum Commoner
Posts: 30
Joined: Sat Nov 27, 2004 10:18 am

PHP Form

Post by seriousdamage »

Hi All,
I have created a very simple web form,
what I would like to do is, when I hit submit beside what was filled in,
I need to send an excel file with it. It will always be the same file, but it needs to be done automaticaly, I do not want to attach it every time.
Can this be done?
Please be aware that my PHP knowledge is very limited.

Thanks
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

try searching these forums [devnet]+mail +file +attach*[/devnet]
seriousdamage
Forum Commoner
Posts: 30
Joined: Sat Nov 27, 2004 10:18 am

Post by seriousdamage »

Hi, Thanks for the help, but I still have a problem, when I get the mail, there is no attachment, please see the code I use

Code: Select all

<?php
<? 
#varibles passed are $username $useraddr $subject $comments $attach 

#open the file 
$fp = fopen ("tiger.xls", "r"); 

#read the file into a variable 
$file = fread($fp, $attach_size); 

#encode the data for safe transit and insert /r/n for 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.="$comment\r\n"; 
$hdr.="--$num\n"; #start boundary here 

#define the attachment section 
$hdr.="Content-Type: $attach_type;"; 
$hdr.="name="$attach_name"\r\n"; 
$hdr.="Content-Transfer-Encoding: base64\r\n"; 
$hdr.="Content-Disposition: attachment; "; 
$hdr.="filename="$attach_name"\r\n\n"; 
$hdr.="$file\r\n"; 
$hdr.="--$num--"; #final boundary here 

#send the email now 
mail($to, $subject, "", $hdr); 

#close the file 
//fclose ($file); 
?> 

?>
Post Reply