Jamcan
04-11-2006, 05:37 PM
Can't seem to get the attached file emailed to me with the content of the form. Form information works fine but no attachment - just a link to the visitor' hard drive
Here is the script for the attached file portion in the php file: -
<?
/*
*/
$mailto = 'timmytiger32@hotmail.com' ;
$subject = "Awardee Nomination" ;
$formurl = "http://www.cast-utech.ca/awardees/nonform.html" ;
$errorurl = "http://www.cast-utech.ca/awardees/err.html" ;
$thankyouurl = "http://www.cast-utech.ca/awardees/thanks.html" ;
$name = $_POST['name'] ;
$address = $_POST['address'] ;
$city = $_POST['city'] ;
$province = $_POST['province'] ;
$postal = $_POST['postal'] ;
$email = $_POST['email'] ;
$telephone = $_POST['telephone'] ;
$start = $_POST['start'] ;
$end = $_POST['end'] ;
$job = $_POST['job'] ;
$utech = $_POST['utech'] ;
$prof = $_POST['prof'] ;
$society = $_POST['society'] ;
$cuaa = $_POST['cuaa'] ;
$community = $_POST['community'] ;
$other = $_POST['other'] ;
$comments = $_POST['comments'] ;
$nomname = $_POST['nomname'] ;
$nomadd = $_POST['nomadd'] ;
$nomcity = $_POST['nomcity'] ;
$nomprov = $_POST['nomprov'] ;
$nomcode = $_POST['nomcode'] ;
$nomemail = $_POST['nomemail'] ;
$nomtele = $_POST['nomtele'] ;
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$http_referrer = getenv( "HTTP_REFERER" );
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
/* Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
*/
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"------------------------- AWARDEE INFORMATION -------------------------\n" .
"Name: -$name\n" .
"Address: -$address\n" .
"City: -$city\n" .
"Province: -$province\n" .
"Postal Code: -$postal\n" .
"E-mail: -$email\n" .
"Telephone: -$telephone\n" .
"Attended Cast from: -$start\n" .
"to: -$end\n" .
"Profession: -$job\n" .
"Contribution: -\n" .
"Utech: -$utech\n" .
"prof: -$prof\n" .
"society: -$society\n" .
"cuaa: -$cuaa\n" .
"community: -$community\n" .
"other: -$other\n" .
"Other Information for this Nominatiom\n" .
"$comments\n" .
// Add file attachment to the message
$comments .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
"----------------------------------------------------------------------\n\n" .
"This message was sent from:\n" .
"$http_referrer\n" .
"By;\n" .
"$nomname\n" .
"$nomadd\n" .
"$nomcity\n" .
"$nomprov\n" .
"$nomcode\n" .
"$nomemail\n" .
"$nomtele\n" .
"\n\n-----------------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper, "From: \"$nomname\" <$nomemail>\nReply-To: \"$nomname\" <$nomemail>\nX-Mailer: chfeedback.php 2.03" );
header( "Location: $thankyouurl" );
exit ;
?>
code in the HTML file: -
<FORM action="feedback.php" method="post" enctype="multipart/form-data">
File Attachment:
<form enctype="multipart/form-data" action="feedback.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="file" name="fileatt">
</form></TD>
Thanks for your help.
(JAMCAN) timmytiger32@hotmail.com
Here is the script for the attached file portion in the php file: -
<?
/*
*/
$mailto = 'timmytiger32@hotmail.com' ;
$subject = "Awardee Nomination" ;
$formurl = "http://www.cast-utech.ca/awardees/nonform.html" ;
$errorurl = "http://www.cast-utech.ca/awardees/err.html" ;
$thankyouurl = "http://www.cast-utech.ca/awardees/thanks.html" ;
$name = $_POST['name'] ;
$address = $_POST['address'] ;
$city = $_POST['city'] ;
$province = $_POST['province'] ;
$postal = $_POST['postal'] ;
$email = $_POST['email'] ;
$telephone = $_POST['telephone'] ;
$start = $_POST['start'] ;
$end = $_POST['end'] ;
$job = $_POST['job'] ;
$utech = $_POST['utech'] ;
$prof = $_POST['prof'] ;
$society = $_POST['society'] ;
$cuaa = $_POST['cuaa'] ;
$community = $_POST['community'] ;
$other = $_POST['other'] ;
$comments = $_POST['comments'] ;
$nomname = $_POST['nomname'] ;
$nomadd = $_POST['nomadd'] ;
$nomcity = $_POST['nomcity'] ;
$nomprov = $_POST['nomprov'] ;
$nomcode = $_POST['nomcode'] ;
$nomemail = $_POST['nomemail'] ;
$nomtele = $_POST['nomtele'] ;
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$http_referrer = getenv( "HTTP_REFERER" );
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
/* Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
*/
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"------------------------- AWARDEE INFORMATION -------------------------\n" .
"Name: -$name\n" .
"Address: -$address\n" .
"City: -$city\n" .
"Province: -$province\n" .
"Postal Code: -$postal\n" .
"E-mail: -$email\n" .
"Telephone: -$telephone\n" .
"Attended Cast from: -$start\n" .
"to: -$end\n" .
"Profession: -$job\n" .
"Contribution: -\n" .
"Utech: -$utech\n" .
"prof: -$prof\n" .
"society: -$society\n" .
"cuaa: -$cuaa\n" .
"community: -$community\n" .
"other: -$other\n" .
"Other Information for this Nominatiom\n" .
"$comments\n" .
// Add file attachment to the message
$comments .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
"----------------------------------------------------------------------\n\n" .
"This message was sent from:\n" .
"$http_referrer\n" .
"By;\n" .
"$nomname\n" .
"$nomadd\n" .
"$nomcity\n" .
"$nomprov\n" .
"$nomcode\n" .
"$nomemail\n" .
"$nomtele\n" .
"\n\n-----------------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper, "From: \"$nomname\" <$nomemail>\nReply-To: \"$nomname\" <$nomemail>\nX-Mailer: chfeedback.php 2.03" );
header( "Location: $thankyouurl" );
exit ;
?>
code in the HTML file: -
<FORM action="feedback.php" method="post" enctype="multipart/form-data">
File Attachment:
<form enctype="multipart/form-data" action="feedback.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="file" name="fileatt">
</form></TD>
Thanks for your help.
(JAMCAN) timmytiger32@hotmail.com