Jump to content

[SOLVED] Sending multiple attachements


drisate

Recommended Posts

Hey guys i am in the process of creating an IMAP webmail and right now i am stuck at creating a multiple attachements feature when you compose your email. At the moment the email is sent out sucessfully but for some reason the attachements are not attached.

 

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;
}

 

I checked if the $_FILES array is empty after it's submited and it's not ... this is a print_r on it

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
                )

        )

)

 

This is the email header of a message suposed to have an attachement but is not ...

Return-path: <betable@dnsadmin.***.***.com>
Envelope-to: patrick@***.org
Delivery-date: Wed, 18 Feb 2009 14:22:12 -0600
Received: from betable by dnsadmin.***.***.com with local (Exim 4.69)
(envelope-from <betable@dnsadmin.***.***.com>)
id 1LZsvs-00088Y-GB
for patrick@***.org; Wed, 18 Feb 2009 14:22:12 -0600
To: patrick@***.org
Subject: patrick@***.org
From: patrick@***.org
Reply-to: <patrick@***.org>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
Message-Id: <E1LZsvs-00088Y-GB@dnsadmin.***.***.com>
Date: Wed, 18 Feb 2009 14:22:12 -0600

 

I really don't get it ... it looks like for some reason the

	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]);
}
}

 

was not looping ... or that Attach() is not adding anything to the header ... This is driving me crazy! What am i missing?

Link to comment
Share on other sites

I just showed someone how to do this a few days ago, and this seemed to work for them. You can pick it apart to work for you:

 

$random_hash = md5(date('r', time())); 
$mime_boundary = "==Multipart_Boundary_x{$random_hash}x"; 
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: multipart/mixed; boundary="'.$mime_boundary.'"' . "\r\n";

// Additional headers
$headers .= 'To: Billy Bob <'.$_POST['to'].'>' . "\r\n";
$headers .= 'From: Jimmy John <jimmyjohn@site.com>' . "\r\n";
// File Info
$message = $_POST['message']."\n\n".
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n"; 
$fileList = '';
foreach ($_FILES["file"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
	$tmp_name = $_FILES["file"]["tmp_name"][$key];
	$name = $_FILES["file"]["name"][$key];	
	$fName = "../attach/".md5(uniqid(rand(), false)).$name;
	move_uploaded_file($tmp_name, $fName);
	$path_parts = pathinfo($fName);
	if($path_parts['extension'] != 'exe'){   // Check for extension type
		$fileatt = $fName; // Path to the file
		$fileatt_type = "application/octet-stream"; // File Type
		$fileatt_name = $name; // Filename that will be used for the file as the attachment
		$file = fopen($fileatt,'rb');
		$data = fread($file,filesize($fileatt));
		fclose($file); 
		$data = chunk_split(base64_encode($data));
		$message .= "--{$mime_boundary}\n" .
		"Content-Type: {$fileatt_type};\n" .
		" name=\"{$fileatt_name}\"\n" .
		//"Content-Disposition: attachment;\n" .
		//" filename=\"{$fileatt_name}\"\n" .
		"Content-Transfer-Encoding: base64\n\n" .
		$data . "\n\n" .
		"--{$mime_boundary}\n";
		unset($data);
		unset($file);
		unset($fileatt);
		unset($fileatt_type);
		unset($fileatt_name);
	}else{
		unlink($fName);  // Remove file if it is an exe
	}
}
}
mail($_POST['to'],$_POST['subject'],$message,$headers);
header('Location: /mail?action=inbox');
exit;

Link to comment
Share on other sites

Nope i get the same problem ...

 

    // 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'];
    
    echo '<pre>';
    print_r($_FILES);
    echo '</pre>';
    
foreach ($_FILES["userfile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
	$tmp_name = $_FILES["userfile"]["tmp_name"][$key];
	$name = $_FILES["userfile"]["name"][$key];	
	$fName = "attach/".md5(uniqid(rand(), false)).$name;
	move_uploaded_file($tmp_name, $fName);
	$path_parts = pathinfo($fName);
	if($path_parts['extension'] != 'exe'){   // Check for extension type
		$fileatt = $fName; // Path to the file
		$fileatt_type = "application/octet-stream"; // File Type
		$fileatt_name = $name; // Filename that will be used for the file as the attachment
		$file = fopen($fileatt,'rb');
		$data = fread($file,filesize($fileatt));
		fclose($file); 
		$data = chunk_split(base64_encode($data));
		$message .= "--{$mime_boundary}\n" .
		"Content-Type: {$fileatt_type};\n" .
		" name=\"{$fileatt_name}\"\n" .
		//"Content-Disposition: attachment;\n" .
		//" filename=\"{$fileatt_name}\"\n" .
		"Content-Transfer-Encoding: base64\n\n" .
		$data . "\n\n" .
		"--{$mime_boundary}\n";
		unset($data);
		unset($file);
		unset($fileatt);
		unset($fileatt_type);
		unset($fileatt_name);
	}else{
		unlink($fName);  // Remove file if it is an exe
	}
}
}

    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']);
        }

 

The email is sent out but not attachements are attached to it

Link to comment
Share on other sites

why do you make $success="true"??

 

Hey hi bro ;-)

 

because of the

 

if ($success) {

 

right after

 

I made a few modifications but still have no result ...

 

    // 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'];
    
    /* // DEBUG STUFF
    echo '<pre>';
    print_r($_FILES);
    echo '</pre>'; */

$random_hash = md5(date('r', time())); 
$mime_boundary = "==Multipart_Boundary_x{$random_hash}x"; 
    
foreach ($_FILES["userfile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
	$tmp_name = $_FILES["userfile"]["tmp_name"][$key];
	$name = $_FILES["userfile"]["name"][$key];	
	$fName = "attach/".md5(uniqid(rand(), false)).$name;
	move_uploaded_file($tmp_name, $fName);
	$path_parts = pathinfo($fName);
	if($path_parts['extension'] != 'exe'){   // Check for extension type
		$fileatt = $fName; // Path to the file
		$fileatt_type = "application/octet-stream"; // File Type
		$fileatt_name = $name; // Filename that will be used for the file as the attachment
		$file = fopen($fileatt,'rb');
		$data = fread($file,filesize($fileatt));
		fclose($file); 
		$data = chunk_split(base64_encode($data));
		$head .= "--{$mime_boundary}\n" .
		"Content-Type: {$fileatt_type};\n" .
		" name=\"{$fileatt_name}\"\n" .
		//"Content-Disposition: attachment;\n" .
		//" filename=\"{$fileatt_name}\"\n" .
		"Content-Transfer-Encoding: base64\n\n" .
		$data . "\n\n" .
		"--{$mime_boundary}\n";
		unset($data);
		unset($file);
		unset($fileatt);
		unset($fileatt_type);
		unset($fileatt_name);
	}else{
		unlink($fName);  // Remove file if it is an exe
	}
}
}

    if ($_POST[submit]!="Save to Drafts"){$success = mail($to, $su, html_entity_decode($ms), $head);}else{$success="true";}

Link to comment
Share on other sites

Ok i tryed inserting the content of the Attache() insde the loop and i finaly got an error that could explain the problem ...

 

I get : Could not open uploaded file on the server

 

foreach ($_FILES["userfile"]["error"] as $key => $error) {

$AttmFile = $_FILES["userfile"]["tmp_name"][$key];
$FileName = $_FILES['userfile']['name'][$key];

    $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.="X-MSMail-Priority: High\n";
    //	$headers.="X-Mailer: OneFile\n";
    $headers .= "Content-Type: multipart/mixed;\n\tboundary=\"" . $OB . "\"\n";
    //Messages start with text/html alternatives in OB
    $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";
    //plaintext section
    $Msg .= "\n--" . $IB . "\n";
    $Msg .= "Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
    $Msg .= "Content-Transfer-Encoding: quoted-printable\n\n";
    // plaintext goes here
    $Msg .= $Text . "\n\n";
    /*
    // html section 
    $Msg.="\n--".$IB."\n";
    $Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
    $Msg.="Content-Transfer-Encoding: base64\n\n";
    // html goes here 
    $Msg.=chunk_split(base64_encode($Html))."\n\n";
    */
    // end of IB
    $Msg .= "\n--" . $IB . "--\n";
    // attachments (dit was eerst een loop, dus dit kan voor meerdere files ook zo)
    // attachments (dit was eerst een loop, dus dit kan voor meerdere files ook zo)
    $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";
    //file goes here
    $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";
    // attachments (dit was eerst een loop, dus dit kan voor meerdere files ook zo)
    // attachments (dit was eerst een loop, dus dit kan voor meerdere files ook zo)
    //message ends
    $Msg .= "\n--" . $OB . "--\n";
    // teruggeven naar global
    $ms = $Msg;
    $head = $headers;
}

 

The reason i did'int see thate rror before was because the die() was in the function

Link to comment
Share on other sites

I have probably asked this before  as I know this is the first time you posted this question.

 

Have you looked into phpMailer or PEAR::Mail (I would go for phpMailer over Pear, but that is an option).

 

Mail()

 

Note: If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package » PEAR::Mail_Mime.

 

I know it is not much help, but that is about all I can think of as I have never needed to send more than 1 attachment at a time via php Mail.

 

Link to comment
Share on other sites

i remade my script and now it works :-) This was one big headack ... thx for your support guys ;-)

 

working multiple attachment

 

<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>

 

$to = $_POST[to];
$su = $_POST[su];
$FromEmail = $_POST[fr];
$txt = html2text($_POST['ms']);
$html = $_POST['ms'];

$boundary1   =rand(0,9)."-"
.rand(10000000000,9999999999)."-"
.rand(10000000000,9999999999)."=:"
.rand(10000,99999);
$boundary2   =rand(0,9)."-".rand(10000000000,9999999999)."-"
.rand(10000000000,9999999999)."=:"
.rand(10000,99999);


for($i=0; $i < count($_FILES['userfile']['name']); $i++){
if(is_uploaded_file($_FILES['userfile']['tmp_name'][$i]) &&
   !empty($_FILES['userfile']['size'][$i]) &&
   !empty($_FILES['userfile']['name'][$i])){
    
$attach      ='yes';
$end         ='';

   $handle      =fopen($_FILES['userfile']['tmp_name'][$i], 'rb');
   $f_contents  =fread($handle, $_FILES['userfile']['size'][$i]);
   $attachment[]=chunk_split(base64_encode($f_contents));
   fclose($handle);

$ftype[]       =$_FILES['userfile']['type'][$i];
$fname[]       =$_FILES['userfile']['name'][$i];
}
}

/***************************************************************
Creating Email: Headers, BODY
1- HTML Email WIthout Attachment!! <<-------- H T M L ---------
***************************************************************/
#---->Headers Part
$Headers     =<<<AKAM
From: $FromName <$FromEmail>
CC: $_POST[cc]
BCC: $_POST[bcc]
Return-Path: <$_POST[fr]>
Reply-To: $FromEmail
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="$boundary1"
AKAM;

#---->BODY Part
$Body        =<<<AKAM
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="$boundary1"

This is a multi-part message in MIME format.

--$boundary1
Content-Type: text/plain;
    charset="windows-1256"
Content-Transfer-Encoding: quoted-printable

$txt
--$boundary1
Content-Type: text/html;
    charset="windows-1256"
Content-Transfer-Encoding: quoted-printable

$html

--$boundary1--
AKAM;

/***************************************************************
2- HTML Email WIth Multiple Attachment <<----- Attachment ------
***************************************************************/

if($attach=='yes') {

$attachments='';
$Headers     =<<<AKAM
From: $FromName <$FromEmail>
CC: $_POST[cc]
BCC: $_POST[bcc]
Return-Path: <$_POST[fr]>
Reply-To: $FromEmail
MIME-Version: 1.0
Content-Type: multipart/mixed;
    boundary="$boundary1"
AKAM;

for($j=0;$j<count($ftype); $j++){
$attachments.=<<<ATTA
--$boundary1
Content-Type: $ftype[$j];
    name="$fname[$i]"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
    filename="$fname[$j]"

$attachment[$j]

ATTA;
}

$Body        =<<<AKAM
This is a multi-part message in MIME format.

--$boundary1
Content-Type: multipart/alternative;
    boundary="$boundary2"

--$boundary2
Content-Type: text/plain;
    charset="windows-1256"
Content-Transfer-Encoding: quoted-printable

$txt
--$boundary2
Content-Type: text/html;
    charset="windows-1256"
Content-Transfer-Encoding: quoted-printable

$html

--$boundary2--

$attachments
--$boundary1--
AKAM;
}

    if ($_POST[submit]!="Save to Drafts"){$success = mail($to, $su, $Body, $Headers);}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']);
        }

$stream = imap_open("{mail.website.org:143/imap/notls}", "$_SESSION[session_username]", "$_SESSION[session_password]");
$check = imap_check($stream);

imap_append($stream, "{mail.website.org:143/imap/notls}INBOX.Sent"
                   , "From: $_POST[fr]\r\n"
                   . "To: $to\r\n"
                   . "Subject: $su\r\n"
                   . "\r\n"
                   . html_entity_decode($ms) . "\r\n"
                   );

if ($_POST[submit]=="Save to Drafts"){
imap_append($stream, "{mail.website.org:143/imap/notls}INBOX.Drafts"
                   , "From: $_POST[fr]\r\n"
                   . "To: $to\r\n"
                   . "Subject: $su\r\n"
                   . "\r\n"
                   . html_entity_decode($ms) . "\r\n"
                   );
}else{
imap_append($stream, "{mail.website.org:143/imap/notls}INBOX.Drafts"
                   , "From: $_POST[fr]\r\n"
                   . "To: $to\r\n"
                   . "Subject: $su\r\n"
                   . "\r\n"
                   . html_entity_decode($ms) . "\r\n"
                   );	
}

$check = imap_check($stream);


imap_close($stream);

if ($_POST[submit]=="Save to Drafts"){
        echo "<META HTTP-EQUIV='Refresh' CONTENT='0;url=?mod=mail&folder=INBOX.Drafts'></META>";
}else{
        echo "<META HTTP-EQUIV='Refresh' CONTENT='0;url=?mod=mail&folder=";
        if (isset($_GET['folder']))
            echo $_GET['folder'];
        echo "'></META>";
}
        //print ("message: <br>".html_entity_decode($ms)."<br><br><hr><br>");

    }
    else
    {
        showBody("");
        echo "MAIL IS NOT SEND, error on the server. ";
        echo "Copy the content of your e-mail below, and try again by <A href='?mod=mail&folder=";
        if (isset($_GET['folder']))
            echo $_GET['folder'];
        echo "'>continuing</a>...<pre>" . $_POST['ms'] . "</pre><br><hr><br>$success";
    }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.