<?
# send an email with an attachment from a php script
# this is a little raw - needs some work.
# one problem is that different email programs read
# attachments differently

$to   = "recipient@somedomain.xxx";
$from = "sender@someotherdomain.xxx";

if(empty($attach)||(empty($subject)||empty($message))){
   print("
<form action=$PHP_SELF method=POST ENCTYPE=multipart/form-data>
<INPUT TYPE=hidden name=MAX_FILE_SIZE value=100000>
<center><table cellpadding=4>
<tr><td>Subject</td><td><input name=subject value=\"$subject\" size=40></td></tr>
<tr><td>Message</td><td><textarea name=message rows=15 cols=40>$message</textarea></td></tr>
<tr><td>Attachment</td><td><input type=file name=attach></td></tr>
<tr><td>&nbsp;</td><td><input type=Submit value=\"Send\"></td></tr>
</table></center></form>
");      
}
else if(file_exists($attach))
{
   $boundary = "------------500B2F613A8F0C0B7A916260";
   $name = rawurldecode(str_replace("+","%20",$attach_name)); 
   $bytes =  filesize($attach);
   $fp = fopen("$attach","r");
   $contents = fread($fp, $bytes);
   fclose($fp);
   $encoded = chunk_split(base64_encode($contents));
   $message = stripslashes($message);
   $subject = stripslashes($subject);   
   $ret = mail($to,$subject,
    "This is a multi-part message in MIME format.
--------------500B2F613A8F0C0B7A916260
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

$message

--------------500B2F613A8F0C0B7A916260
Content-Type: $attach_type; name=\"$name\"
Content-Transfer-Encoding: base64
Content-Description: Unknown Document
Content-Disposition: inline; filename=\"$name\"

$encoded

--------------500B2F613A8F0C0B7A916260--

",
   "From: $from\nReply-To: $from\nContent-Type: multipart/mixed; boundary=$boundary");
   if($ret) print("Sent mail. Thanks.");
   else     print("Mail error!");
}
else

   $ret = mail($to,$subject,$message,"From: $from\nReply-To: $from");
   if($ret) print("Sent mail. Thanks.");
   else     print("Mail error!");
}

?>