Hi all, i've been struggling with creating a form that lets you add an
attachment and the attachment is sent via email.. I was wondering if
recieving attachments in an md5 form is the only way to do this.. It's
all i've found in my searching. All my attachments are going to be
..gifs or .jpegs... Thanks in advance.
below is the code:
<?php
foreach($_POST as $key => $value)
{
$$key = stripslashes($v alue);
}
$userfile = $_FILES['userfile']['tmp_name'];
$userfile_type = $_FILES['userfile']['type'];
$userfile_name = $_FILES['userfile']['name'];
$userfile_size = $_FILES['userfile']['size'];
$userfile_error = $_FILES['userfile']['error'];
if(is_uploaded_ file($userfile) )
{
if($userfile_ty pe !== "image/pjpeg" && $userfile_type !== "image/jpeg"
&& $userfile_type !== "image/gif" || $userfile_size > $MAX_FILE_SIZE)
{
echo "There were some problems with the form you submitted.";
if($userfile_ty pe !== "image/pjpeg" && $userfile_type !==
"image/jpeg" && $userfile_type !== "image/gif")
{
echo '<p>You may only upload an image, either a GIF or
JPG.</p>\n';
echo "<p>Uploade d: $userfile_name, $userfile_type</p>\n";
}
if($userfile_si ze > $MAX_FILE_SIZE)
{
"<p>Sorry, you may not upload files greater than "
..($MAX_FILE_SI ZE/1024). " KB, the file you uploaded is "
..round(($userf ile_size/1024),1). " KB</p>\n";
}
include("update .php");
exit();
}
}
$hdrs = "From: $email";
$myemail = "$email";
$subject = "Update Form" ;
$msg = " Business Name: $company \n
URL: $url \n
Email: $email \n
Page to Update: $page \n
Changes: $changes
";
$hdrs = "From: $email\r\n";
$orig = fopen($userfile ,'rb');
$file = fread($orig,fil esize($userfile ));
$file = chunk_split(bas e64_encode($fil e));
fclose($orig);
$bndry = "=====FormMaile r".md5(time()). "=====";
$hdrs .= "\nMIME-VERSION: 1.0\n" .
"Content-Type: multipart/mixed;\n boundary=\"$bnd ry\";";
$msg .= "This is a multi-part message in MIME format.\n\n" .
"--$bndry\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$msg .
"--$bndry\n" .
"Content-Type: $userfile_type; \n name=\"$userfil e_name\"\n" .
"Content-Disposition: attachment;\n
filename=\"$use rfile_name\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$file .
"\n--$bndry";
mail($myemail, $subject, $msg, $hdrs);
?>
attachment and the attachment is sent via email.. I was wondering if
recieving attachments in an md5 form is the only way to do this.. It's
all i've found in my searching. All my attachments are going to be
..gifs or .jpegs... Thanks in advance.
below is the code:
<?php
foreach($_POST as $key => $value)
{
$$key = stripslashes($v alue);
}
$userfile = $_FILES['userfile']['tmp_name'];
$userfile_type = $_FILES['userfile']['type'];
$userfile_name = $_FILES['userfile']['name'];
$userfile_size = $_FILES['userfile']['size'];
$userfile_error = $_FILES['userfile']['error'];
if(is_uploaded_ file($userfile) )
{
if($userfile_ty pe !== "image/pjpeg" && $userfile_type !== "image/jpeg"
&& $userfile_type !== "image/gif" || $userfile_size > $MAX_FILE_SIZE)
{
echo "There were some problems with the form you submitted.";
if($userfile_ty pe !== "image/pjpeg" && $userfile_type !==
"image/jpeg" && $userfile_type !== "image/gif")
{
echo '<p>You may only upload an image, either a GIF or
JPG.</p>\n';
echo "<p>Uploade d: $userfile_name, $userfile_type</p>\n";
}
if($userfile_si ze > $MAX_FILE_SIZE)
{
"<p>Sorry, you may not upload files greater than "
..($MAX_FILE_SI ZE/1024). " KB, the file you uploaded is "
..round(($userf ile_size/1024),1). " KB</p>\n";
}
include("update .php");
exit();
}
}
$hdrs = "From: $email";
$myemail = "$email";
$subject = "Update Form" ;
$msg = " Business Name: $company \n
URL: $url \n
Email: $email \n
Page to Update: $page \n
Changes: $changes
";
$hdrs = "From: $email\r\n";
$orig = fopen($userfile ,'rb');
$file = fread($orig,fil esize($userfile ));
$file = chunk_split(bas e64_encode($fil e));
fclose($orig);
$bndry = "=====FormMaile r".md5(time()). "=====";
$hdrs .= "\nMIME-VERSION: 1.0\n" .
"Content-Type: multipart/mixed;\n boundary=\"$bnd ry\";";
$msg .= "This is a multi-part message in MIME format.\n\n" .
"--$bndry\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$msg .
"--$bndry\n" .
"Content-Type: $userfile_type; \n name=\"$userfil e_name\"\n" .
"Content-Disposition: attachment;\n
filename=\"$use rfile_name\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$file .
"\n--$bndry";
mail($myemail, $subject, $msg, $hdrs);
?>
Comment