Code:
<?php
//mail formulier voor bijlage
$email ='my@email.com';
//geneer boundary
DEFINE('bound',md5(uniqid(time())));
//check request method
if($_SERVER['REQUEST_METHOD'] ==
'POST')
{
//if file upload send with email as mixed
if(!empty($_FILES['file']['name']))
{
//check filesize
if($_FILES['file']['size'] < 1024*50)
{
$headers = "From: ".$_POST['from']
." <".$_POST['email'].">\r\n";
$headers .= "Reply-To: ".$_POST
['from']." <".$_POST['email'].">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
//email exist out of more parts, some
thing (can't say it in english) show's php it's multipart
$headers .= "Content-Type: multipart/
mixed; boundary=\"".bound."\"\r\n";
//we send the attachment
$headers .= "Content-Disposition:
attachment\r\n";
//readfile
$fp = fopen($_FILES['file']
['tmp_name'],'r');
$bestand = fread($fp,$_FILES['file']
['size']);
fclose($fp);
//create body
//generating a body. Dit is some multi
part bull****
$body.= "This is a multi-part message
in MIME format.\r\n";
$body.= "\r\n";
//boundary
$body.= "--".bound."\r\n";
//content type + charater set (iso in this
case)
$body.= "Content-Type: text/plain;
charset=iso-8859-1\r\n";
//coding (7 bit)
$body.= "Content-Transfer-Encoding:
7bit\r\n";
$body.= "\r\n";
//the message
$body.= $_POST['bericht'] ."\r\n";
//boundary
$body.= "--".bound."\r\n";
//content typ + name file (database.sql)
$body .= "Content-Type: application/
octet-stream; name=".$_FILES['file']['name']."\r\n";
//coding
$body .= "Content-Transfer-Encoding:
base64\r\n";
//add the attachment
$body.= "Content-disposition:
attachment\r\n";
$body .= "\n";
//the content of the file
$body .= chunk_split(base64_encode($
bestand )) . "\r\n";
mail($email,$_POST['subject'],$body,$
headers);
echo 'Email (With attachment) is send';
}
else
{
echo 'File is too large';
}
}
else
{
$headers = "From: ".$_POST['from']."
<".$_POST['email'].">\r\n";
$headers .= "Reply-To: ".$_POST
['from']." <".$_POST['email'].">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$bericht = $_POST['bericht'];
mail($email,$_POST['subject'],$bericht,$
headers);
echo 'Email (Without attachement) is
send';
}
}
else
{
//mailform
echo "<form action=\"" . $_SERVER
['PHP_SELF'] . "\" method=\"POST\"
enctype=\"multipart/form-data\">";
echo "Name: <input type='text'
name='from'><br>";
echo "Email:<input type='text'
name='email'><br>";
echo "Subject:<input type='text'
name='subject'><br>";
echo "File:<input type='file'
name='file'><br>";
echo "Message:<textarea name='bericht'></
textarea><br />";
echo "<input type=\"submit\"
value=\"Send\">";
}
?>
with this script you can let people send you an attachment by mail
you will have to change
my@email.com in your real email adress
I sugest you don't change anything else exept if you know what you are doing