hello I have been developing a webmail
program. I have succsesfuly created a compose script that sends attachments. I have a problem, When I send an attachment I
can receve it in pine or Outlook but not my
webmail program. If i send an attachment from pine or outlook I can receve the attachment in my webmail program. I think I
just need someone to look at my code to see my mistake. Here is some sloppy code, I have not created the functions yet becuse i have not been 100% succssessfull.
Sending the mail
<code>
// register variables
$file = $HTTP_POST_FILES['file']['name'];
$type = $HTTP_POST_FILES['file']['type'];
$size = $HTTP_POST_FILES['file']['size'];
$temp = $HTTP_POST_FILES['file']['tmp_name'];
$size_limit = "10000"; // set size limit in bytes
if ($file){
if ($size < $size_limit){
if($file){
$fp=fopen("$temp","r");
$info=fread($fp, $size);
//$boundary = 'tw'.chr(rand(65, 91)).'------'.md5(uniqid(rand()));
$boundary = '----=_tw_'.md5(uniqid(rand()));
//headers//
$headers = "Return-Path: $user@$from";
$headers .= "From: $user@$from";
$headers .= "Subject: $subject";
$headers .= "MIME-Version: 1.0 \r\n";
$headers .= "Content-Type: multipart/mixed; \n\t boundary=\"$boundary\"\n";
//body//
$main = "This is a multipart MIME Message \n\n";
$main .= '--'.$boundary;
$main .= "\n";
$main .= "Content-Type: multipart/alternative;\n\t boundary=\"$boundary\"\n";
$main .= "\n\n";
$main .= '--'.$boundary;
$main .= "\nContent-Type: text/plain;\n\t charset=\"iso-8859-1\"";
$main .= "\nContent-Transfer-Encoding: quoted-printable\n";
$main .= "\n";
$main .= "$body\n";
$main .= "\n\n";
$main .= '--'.$boundary;
$main .= "\nContent-Type: text/html;\n\t charset=\"iso-8859-1\"";
$main .= "\nContent-Transfer-Encoding: quoted-printable\n";
$main .= "\n";
$main .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
<HEAD>
<META content=3D\"text/html; charset=3Diso-8859-1\" =http-equiv=3DContent-Type>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>";
$main .= "$body</body>\n";
$main .= "\n";
$main .= '--'.$boundary.'--';
$main .= "\n\n";
$main .= '--'.$boundary;
$main .= "\nContent-Type: $type; \n\t name=\"$file\"";
$main .= "\nContent-Transfer-Encoding: base64";
$main .= "\nContent-Disposition: attachment;\n\tfilename=\"$file\"\n\n";
$main .= chunk_split(base64_encode($info));
$main .= "\n";
$main .= '--'.$boundary.'--';
mail($to, $subject, $main, "$headers", "-f$user@$from");
and here is the code to receve the mail.
<code>
<?
session_start();
//View mesage body//
echo "<head>
<style>
a {color: #000000; text-decoration: none;}";
include("colors");
echo "</style></head>";
//Echo head//
echo "<body BGColor=#cfcfcf>";
echo "<table width=20% BGColor=#ffffff height=500 align=left>
<tr>
<td class=nav height=10></td>
</tr>
<tr valign=top>
<td>";
include("links.php");
echo " </td>
</tr>
<tr>
<td class=nav></td>
</tr>
</table>";
echo "<table width=80% bgcolor=#ffffff>
<tr>
<td colspan=100 class=head height=40>";
echo "<font color=#000000>Welcome $user you are reading message #$num.</font><br>";
echo " </td>
</tr>";
//End head//
$link=imap_open("{$server/pop3:110}INBOX", "$user", "$pass",OP_SILENT);
$attach=imap_fetchstructure($link, $num);
$type1=imap_fetchbody($link, $num, 1.2);
$type2=imap_fetchbody($link, $num, 2);
$body = $type1;
$view=imap_base64($body);
//Functions for attachments//
$attachment=$attach->parts;
echo "<tr>";
if($attachment)
{
while (list ($key, $val) = each ($attachment)) {
//subtype & type//
$type=$val->type;
$subtype=$val->subtype;
//echo "<br>";
$multi=$val->disposition;
if($multi == "ATTACHMENT")
{
$dis=$val->dparameters;
while (list ($key, $val) = each ($dis)) {
$name=$val->value;
echo "<td><a href=down.php?num=$num&type=$type&subtype=$subtype&name=$name><font color=blue>[ $name ]</font></a></td>";
}
}
}
}
echo "</tr>";
//$body2 = explode("------", $body);
//$body3 = imap_binary($body);
print(" <tr>
<td BGColor=#ffffff colspan=100>
<table>");
print(" <tr>
<td><pre>$body<bR>");
print (" </pre></td>
</tr>
</table>
</td>
</tr>
");
//footer//
print("<tr><td colspan=100 class=footer height=20>");
//include("footer.php");
print("</td></tr>");
//end footer//
print("</table>");
imap_close($link);
?>
</code>
any ideas ????