Jump to content

attachements


drisate

Recommended Posts

Hey guys i am having a hard time adding my attachements to my email using IMAP

 

elseif ($_GET['CMD'] == "send")
{
    // 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']);
        }

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

imap_append($stream, "{mail.blessingstairs.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.blessingstairs.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.blessingstairs.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>");

    }

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.="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;
}

Link to comment
Share on other sites

Yeah from what i know the r is ok ... i really don't get it because the Attach($AttmFile, $FileName) function comes from a working webmail so it should normaly work  ... (it does on the other webmail) ... So the problem is moste likly from the processing before that

 

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

}

}

 

the imput boxes are like this

 

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

[...]

 

The email is sent but not the attachements

Link to comment
Share on other sites

Yeah i am heres what my code looks like. It's basacly a Gmail attachement like form ... you can add or remove attachement boxes. Works like a charme ... it's really just the processing part that is causing me troble

 

<?xml version="1.0"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr" >
<head>
  <meta name="robots" content="index, follow" />
  <meta name="keywords" content="BlessingStairs" />
  <meta name="description" content="BlessingStairs" />
  <meta name="generator" content="Microsoft FrontPage 5.0" />
  <title>Welcome to the Frontpage</title>
  <link href="/index.php?format=feed&type=rss" rel="alternate" type="application/rss+xml" title="RSS 2.0" />

  <link href="/index.php?format=feed&type=atom" rel="alternate" type="application/atom+xml" title="Atom 1.0" />
  <link href="/templates/theme176/favicon.ico" rel="shortcut icon" type="image/x-icon" />
  <script type="text/javascript" src="/includes/js/joomla.javascript.js"></script>
  <script type="text/javascript" src="/media/system/js/mootools.js"></script>
  <script type="text/javascript" src="/media/system/js/caption.js"></script>


<link type="text/css" rel="stylesheet" href="/templates/theme176/css/board.css" />
  <script type="text/javascript" src="/plugins/editors/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

<script type="text/javascript">
		tinyMCE.init({
		theme : "advanced",
		language : "en",
		mode : "textareas",
		gecko_spellcheck : "true",
		editor_selector : "mce_editable",
		document_base_url : "/",
		entities : "60,lt,62,gt",
		relative_urls : 1,
		remove_script_host : false,
		save_callback : "TinyMCE_Save",
		invalid_elements : "applet",
		extended_valid_elements : "a[class|name|href|target|title|onclick|rel],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],,hr[id|title|alt|class|width|size|noshade]",
		theme_advanced_toolbar_location : "top",
		theme_advanced_source_editor_height : "550",
		theme_advanced_source_editor_width : "580",
		directionality: "ltr",
		force_br_newlines : "true",
		force_p_newlines : "false",
		content_css : "/templates/system/css/editor.css",
		debug : false,
		cleanup : true,
		cleanup_on_startup : true,
		safari_warning : false,
		plugins : "advlink, advimage, searchreplace,insertdatetime,emotions,media,advhr,table,fullscreen,directionality,layer,style",
		theme_advanced_buttons1_add : "fontselect",
		theme_advanced_buttons2_add : "search,replace,insertdate,inserttime,emotions,media,ltr,rtl,insertlayer,moveforward,movebackward,absolute,forecolor",
		theme_advanced_buttons3_add : "advhr,tablecontrols,fullscreen,styleprops",
		theme_advanced_disable : "help",
		plugin_insertdate_dateFormat : "%Y-%m-%d",
		plugin_insertdate_timeFormat : "%H:%M:%S",


		fullscreen_settings : {
			theme_advanced_path_location : "top"
		}
	});
	function TinyMCE_Save(editor_id, content, node)
	{
		base_url = tinyMCE.settings['document_base_url'];
		var vHTML = content;
		if (true == true){
			vHTML = tinyMCE.regexpReplace(vHTML, 'href\s*=\s*"?'+base_url+'', 'href="', 'gi');
			vHTML = tinyMCE.regexpReplace(vHTML, 'src\s*=\s*"?'+base_url+'', 'src="', 'gi');
			vHTML = tinyMCE.regexpReplace(vHTML, 'mce_real_src\s*=\s*"?', '', 'gi');
			vHTML = tinyMCE.regexpReplace(vHTML, 'mce_real_href\s*=\s*"?', '', 'gi');
		}
		return vHTML;
	}
  </script>


<link rel="stylesheet" href="/administrator/templates/system/css/system.css" type="text/css" />
<link href="/administrator/templates/khepri/css/template.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="/uploads.css" type="text/css" />
<script type="text/javascript" src="/uploads.js"></script>



<link rel="stylesheet" href="/templates/theme176/css/template.css" type="text/css" />
<link rel="stylesheet" href="/templates/theme176/css/constant.css" type="text/css" />
<link rel="stylesheet" href="/templates/theme176/css/style.css" type="text/css" />



</head>
<body>

<div class="comp-cont">
<form action='index.php?mod=mail&CMD=send' enctype='multipart/form-data' method='post'>
    <input type='hidden' name='fr' value='patrick@blessingstairs.org'>
<input type='hidden' name='MAX_FILE_SIZE' value='2480000021'>
<table border='0' cellpadding='3' cellspacing='3' width='100%'>
	<tr>
		<td width='105'>Attachment:</td>
		<td><div id="attachment" class="attachment" style="display:none">

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
  <tr>
    <td width="100%">
    <input  id="file" name='userfile[]' style="background-color: #ddeeee;"type="file" type='file' size="55"> <a href="#" onclick="javascript:removeFile(this.parentNode.parentNode,this.parentNode);">remove</a></td>

  </tr>
</table>

</div>

<div id="attachments" class="container"><br/><a id="addupload" href="javascript:addUpload(10, 'desc', 'file')">
  <img src='/images/trombone2.png' width="30" height="30"> Click here to attach a file</a><br/><br/>
<span id="attachmentmarker"></span>
</div>
</td>
	</tr>
	</table>
</form>									

</div>

</body>
</html>

Link to comment
Share on other sites

Yeah the $_FILES is not empty

 

    echo '<pre>';
    print_r($_FILES);
    echo '</pre>';

 

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
                )

        )

)

Mail is sent!

Link to comment
Share on other sites

lol no i am not hehe this is driving me crazy >.<

I have been looking for a solution all day ...

 

I think i posted almost 50 messages just today i was helping others hopping somebody would help me :-(

 

yeah I know you have, and there have also been posts about attachments as well....

 

I'm just shocked that no one else is able to provide any insight...surely someone has experience in this area?

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.