Jump to content

Multiple IMAP file attachements to outgoing email


drisate

Recommended Posts

Hey guys i am trying to create a Gmail multiple attachement clone systeme to my webmail and i am having a hard time with adding mutiple attachements to my emails. The email is sent, but no attachements are sent out with it...

 

My HTML form looks like this:

<form action='index.php?mod=mail&CMD=send' enctype='multipart/form-data' method='post'>
<input id="file" name="userfile[]" style="background-color: rgb(221, 238, 238);" size="55" type="file">
<input id="file" name="userfile[]" style="background-color: rgb(221, 238, 238);" size="55" type="file">
<input id="file" name="userfile[]" style="background-color: rgb(221, 238, 238);" size="55" type="file">
<input id="file" name="userfile[]" style="background-color: rgb(221, 238, 238);" size="55" type="file">
<input id="file" name="userfile[]" style="background-color: rgb(221, 238, 238);" size="55" type="file">
[...]
</form>

 

My PHP code that gets this looks like this:

<?php

    // SOME SERVERS HAVE SOME DIFFERENCES - AGHR
    if (get_magic_quotes_gpc())
        $_POST = array_map('stripslashes', $_POST);
    $_POST['ms'] = str_replace("\r\n", "\n", $_POST['ms']);
    if (!isset($_SESSION['session_server']) || !isset($_SESSION['session_username']) ||
        !isset($_SESSION['session_password']))
    {
        showBody("");
        echo "Your session might have timed-out. ";
        echo "Copy the content of your e-mail below, and try again by <A href='?mod=mail&folder=$_GET[folder]'>continuing</a>...";
        echo "<PRE>" . $_POST['ms'] . "</PRE>";
        return;
    }
    $head = "From: $_POST[fr]\n";
    if ($_POST['cc']){$head .= "CC: $_POST[cc]\n";}
    if ($_POST['bcc']){$head .= "BCC: $_POST[bcc]\n";}
    $head .= "Return-Path: <" . $_POST['fr'] . ">\n";
    $head .= "Reply-to: <" . $_POST['fr'] . ">\n";
    $head .= 'Content-Type: text/html; charset="iso-8859-1"' . "\n";
    $head .= 'Content-Transfer-Encoding: 8bit';
    $head = str_replace("'", '"', $head);

    $to = str_replace("'", '"', $_POST['to']);
    $su = stripslashes($_POST['su']);
    $ms = $_POST['ms'];
foreach($_FILES['userfile']['tmp_name'] as $key => $value){
if (is_uploaded_file($_FILES['userfile']['tmp_name'][$key])) {
	Attach($_FILES['userfile']['tmp_name'][$key],$_FILES['userfile']['name'][$key]);
}
}
    if ($_POST[submit]!="Save to Drafts"){$success = mail($to, $su, html_entity_decode($ms), $head);}else{$success="true";}
    if ($success)
    {
        showBody("");
        if ($_POST[submit]!="Save to Drafts"){echo "Mail is sent!";}else{echo "Mail is saved!";}
        if (isset($_POST['oldmessage']) && isset($_POST['oldmessage_delete']) && $_POST['oldmessage_delete'] ==
            "true")
        {
            echo " Also deleting original message.";
            delete($_POST['oldmessage']);
        }

}

?>

 

In case you are wandering what the Attach function does ...

function Attach($AttmFile, $FileName)
{
    global $ms, $head;// orginele message en headers
    $Text = $ms;
    $Html = $ms;// html is niet meer actief want wordt niet goed weergegeven na invoer
    if ($Text == "")
    {
        $Text = " ";
        $Html = " ";
    }
    $OB = "----=_OuterBoundary_000";
    $IB = "----=_InnerBoundery_001";
    $Html = $Html ? $Html:preg_replace("/\n/", "{br}", $Text) or die("neither text nor html part present.");
    $Text = $Text ? $Text:"Sorry, but you need an html mailer to read this mail.";
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= $head;// toevoeging orginele headers (from en to enzo)
    $headers .= "X-Priority: 1\n";
    $headers .= "Content-Type: multipart/mixed;\n\tboundary=\"" . $OB . "\"\n";
    $Msg = "This is a multi-part message in MIME format.\n";
    $Msg .= "\n--" . $OB . "\n";
    $Msg .= "Content-Type: multipart/alternative;\n\tboundary=\"" . $IB . "\"\n\n";
    $Msg .= "\n--" . $IB . "\n";
    $Msg .= "Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
    $Msg .= "Content-Transfer-Encoding: quoted-printable\n\n";
    $Msg .= $Text . "\n\n";
    $Msg .= "\n--" . $IB . "--\n";
    $patharray = explode("/", $AttmFile);
    $Msg .= "\n--" . $OB . "\n";
    $Msg .= "Content-Type: application/octetstream;\n\tname=\"" . $FileName . "\"\n";
    $Msg .= "Content-Transfer-Encoding: base64\n";
    $Msg .= "Content-Disposition: attachment;\n\tfilename=\"" . $FileName . "\"\n\n";
    $fd = fopen($AttmFile, "r");
    if (!$fd)
        die("Could not open uploaded file on the server");
    $FileContent = fread($fd, filesize($AttmFile));
    fclose($fd);
    $FileContent = chunk_split(base64_encode($FileContent));
    $Msg .= $FileContent;
    $Msg .= "\n\n";
    $Msg .= "\n--" . $OB . "--\n";
    $ms = $Msg;
    $head = $headers;
}

 

When i submit the forme the $_FILES is well sorted this is my print_r

Array
(
    [userfile] => Array
        (
            [name] => Array
                (
                    [0] => 
                    [1] => patangel.jpg
                    [2] => patangel.png
                    [3] => Picture 1.jpg
                )

            [type] => Array
                (
                    [0] => 
                    [1] => image/pjpeg
                    [2] => image/x-png
                    [3] => image/pjpeg
                )

            [tmp_name] => Array
                (
                    [0] => 
                    [1] => /tmp/phpITuenD
                    [2] => /tmp/phpDVBoEJ
                    [3] => /tmp/phpQ3phKT
                )

            [error] => Array
                (
                    [0] => 4
                    [1] => 0
                    [2] => 0
                    [3] => 0
                )

            [size] => Array
                (
                    [0] => 0
                    [1] => 66131
                    [2] => 160980
                    [3] => 102651
                )

        )

)

 

I really don't get what i did wroung ... your help is really appreciated. thanks in advance.

YES PLEEEAASE ! hehe

Let's hope i get more luck today :-)

 

 

You must have pissed of some people around here if no one can help you with this issue. There are more than enough guru's floating around...

 

WHAT DID YOU DO!!!!??  hahaha

Nothing i swear hehe

I guess this is just to "hard" for them as well :P

 

Well let's hope this isn't something absolutely critical and your job needs it ASAP.....

 

You might have to wait awhile to get some help!!!

 

This is kind of annoying because it is really urgent ... i need this attachement feature fixed as soon as possible...

 

 

This is kind of annoying because it is really urgent ... i need this attachement feature fixed as soon as possible...

 

Ok, well I don't know this guy, but he seems to know his PHP. I've never contacted before but I do read his blogs.

 

Maybe you should try contacting him??

 

http://blog.preinheimer.com/

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.