Page 1 of 1
PHP Form
Posted: Sun Nov 28, 2004 10:33 am
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
Posted: Sun Nov 28, 2004 11:53 am
by Archy
Posted: Sun Nov 28, 2004 1:02 pm
by John Cartwright
try searching these forums [devnet]+mail +file +attach*[/devnet]
Posted: Sun Nov 28, 2004 1:44 pm
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);
?>
?>