why is my form submitting to an excel file?
Okay all, I have a form that I want users to fill out. When They click submit, I want the contents of this form to be put into a message, and I want the contents to be added to an excel file. Then I want the message that is sent to the recipient to have an attachment of that excel file. You will see partial mime code, I have no Idea how to use it, that was my attempt at figuring this out... Heres what I have so far:
I guess the main question is more specifically, what in the code is making the contents the user submits, automatically go into an excel file and attach itself to the email?
$date = $_POST['date'];
$org =$_POST['Org'];
$activity =$_POST['activ'];
$dofevent = $_POST['dateoe'];
$money= $_POST['amountreq'];
$name =$_POST['name'];
$email =$_POST['email'];
$phone =$_POST['pnumber'];
$dateneeded =$_POST['datenb'];
//bottom
$semester =$_POST['semester'];
$question7a =$_POST['7a'];
$question7b =$_POST['7b'];
$mime_boundary = "<<<--==+X[".md5(time())."]";
$headers .= "From: SAF Request Form ";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
//$headers .= " boundary=\"".$mime_boundary."\"";
$subject .="SAF Request Form";
//$message .= "This is a multi-part message in MIME format.\r\n";
//$message .= "\r\n";
//$mes开发者_JAVA技巧sage .= "--".$mime_boundary."\r\n";
//$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
//$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message ="this is where I put my message";
mail ("20valvesofturbo@gmail.com",$subject,$message, $headers);
if( mail( "20valvesofturbo@gmail.com", $subject, $message, $headers ) ) {
echo "<p>The email was sent.</p>";
}
else {
echo "<p>There was an error sending the mail.</p>";
}
// start of xcel spreadsheet and header-->
$reg = "../data/eforms/saf/reg.xls";
$ft = fopen($reg,'a');
fwrite($ft,"header information");
// start of information submitted by user
fwrite($ft, $org);
fwrite($ft,"user submitted data");
fclose($ft);
//adds all the data
// individual excell sheet
$reg = "../data/eforms/saf/names/$org.xls";
$ft = fopen($reg,'w+');
fwrite($ft,"blablabla");
fclose($ft);
?>
what this does is it submits the data and sends a message, but it sends the data in an unknown file format as an attachment. If you open it in excel, it has the contents of the message...
Thanks!
For generating MIME encoded messages, I suggest that you use the Pear::Mail_Mime package ( http://pear.php.net/package/Mail_Mime). As for generating an Excel file, you can have a look at http://pear.php.net/package/Spreadsheet_Excel_Writer; depending on the complexity of the data to put into Excel, you could possibly also use just a CSV file
精彩评论