Mail versenden IMAP

padde77

Grünschnabel
Hi Forum,

ich hab ein IMAP Konto.
Wenn ich nun Mails versende, geht das ja nicht direkt über das Konto, oder?
Ich muss meiner Meinung nach ja auf die mail() Funktion zurückgreifen. Nur wie bekomm ich die Mail auch in den Ausgangsordner verschoben?

Oder mache ich nen Denkfehler?

Danke
padde
 
Hi, willkommen im Forum.

Verschickt wird ja grundsaetzlich ueber SMTP. IMAP ist ja, genau wie POP, nur ein Protokoll zum abholen der Mails.
Du musst also nach dem Versand eine Kopie der Mail in Sent Items anlegen.
Ich schau gleich mal, ich hab da irgendwo irgendwas zu, das poste ich dann mal.

So, hier mal die sendmail.php aus meinem Web-Mailer.
PHP:
<?php
require_once('email.class.php');
if ((empty($_SESSION['username'])) || (empty($_SESSION['password'])))
	{
		header('Location:index.php');
		exit;
	}
$attachedfiles=array();
$mailto='';
$subject='';
$message='';
if (isset($_GET['edit']))
	{
	}
if (isset($_GET['forward']))
	{
		$mbox=imap_open('{'.MAILHOST.'/norsh/notls}'.$mailbox,$_SESSION['username'],decryptpw($_SESSION['password']));
		$header=imap_header($mbox,$_GET['forward']);
		$body=imap_fetchbody($mbox,$_GET['forward'],1);
		if (isset($header->from[0]->personal))
			{
				$sender=$header->from[0]->personal.' &lt;'.$header->from[0]->mailbox.'@'.$header->from[0]->host.'&gt;';
			}
		else
			{
				$sender=$header->from[0]->mailbox.'@'.$header->from[0]->host;
			}
		$subject='FW: '.$header->subject;
		$message='Original message from '.$sender.":\n";
		$message.=str_replace("\r\n","\n",$body);
		imap_close($mbox);
	}
if (isset($_GET['replyto']))
	{
		$mbox=imap_open('{'.MAILHOST.'/norsh/notls}'.$mailbox,$_SESSION['username'],decryptpw($_SESSION['password']));
		$header=imap_header($mbox,$_GET['replyto']);
		$body=imap_fetchbody($mbox,$_GET['replyto'],1);
		if (isset($header->from[0]->personal))
			{
				$mailto=$header->from[0]->personal.' &lt;'.$header->from[0]->mailbox.'@'.$header->from[0]->host.'&gt;';
			}
		else
			{
				$mailto=$header->from[0]->mailbox.'@'.$header->from[0]->host;
			}
		$subject='RE: '.$header->subject;
		$message="Original message:\n";
		$message.=str_replace("\r\n","\n",$body);
		imap_close($mbox);
	}
if (!empty($_POST))
	{
		$keys=array_keys($_POST);
		for ($count=0;$count<count($keys);$count++)
			{
				if (substr($keys[$count],0,10)=='attachment')
					{
						$attachedfiles[]=$_POST[$keys[$count]];
					}
			}
	}
if ((isset($_POST['attachfile'])) || (isset($_POST['removeattachment'])))
	{
		if (!empty($_POST['mailto']))
			{
				$mailto=$_POST['mailto'];
			}
		if (!empty($_POST['subject']))
			{
				$subject=$_POST['subject'];
			}
		if (!empty($_POST['message']))
			{
				$message=$_POST['message'];
			}
		if (isset($_POST['attachfile']))
			{
				$tmpname=$_FILES['uploadfile']['tmp_name'];
				$filename=$_FILES['uploadfile']['name'];
				$filesize=$_FILES['uploadfile']['size'];
				if ($filesize>0)
					{
						if (!file_exists('mailtemp/'.session_id()))
							{
								createtempdir();
							}
						storetempfile($tmpname,$filename);
						$attachedfiles[]=$filename;
					}
			}
		if (isset($_POST['removeattachment']))
			{
				for ($count=0;$count<count($keys);$count++)
					{
						if (substr($keys[$count],0,13)=='delattachment')
							{
								$filename=$_POST[$keys[$count]];
								$delpositions[]=substr($keys[$count],13,1);
								removetempfile($filename);
							}
					}
				$newattachedfiles=array();
				for ($count=0;$count<count($attachedfiles);$count++)
					{
						if (!in_array($count,$delpositions))
							{
								$newattachedfiles[]=$attachedfiles[$count];
							}
					}
				$attachedfiles=$newattachedfiles;
				unset($newattachedfiles);
			}
	}
if (((isset($_POST['sendmail'])) || (isset($_POST['savedraft']))) && ((!empty($_POST['mailto'])) && (!empty($_POST['subject'])) && (!empty($_POST['message']))))
	{
		$from=$_SESSION['username'];
		if (strpos($from,'@')===false)
			{
				$from.='@'.DOMAIN;
			}
		$mailto=$_POST['mailto'];
		if (strpos($mailto,'@')===false)
			{
				$mailto.='@'.DOMAIN;
			}
		$mail=new email($from,$mailto,$_POST['subject'],$_POST['message']);
		for ($x=0;$x<count($attachedfiles);$x++)
			{
				$mail->addattachment('mailtemp/'.session_id().'/'.$attachedfiles[$x]);
			}
		if (isset($_POST['sendmail']))
			{
				$smtp=new smtpconnection(MAILHOST,SMTPAUTH,$_SESSION['username'],decryptpw($_SESSION['password']),SSLCONNECT);
				$smtp->sendmail($mail->composemail());
				unset($smtp);
			}
		if (((isset($_POST['sendmail'])) && (isset($_POST['savesent']))) || (isset($_POST['savedraft'])))
			{
				if ((isset($_POST['savedraft'])) && (getfolder('Drafts')!=false))
					{
						$mbox=imap_open('{'.MAILHOST.'/norsh/notls}'.getfolder('Drafts'),$_SESSION['username'],decryptpw($_SESSION['password']));
						imap_append($mbox,'{'.MAILHOST.'}'.getfolder('Drafts'),$mail->composemail());
						$mboxinfo=imap_mailboxmsginfo($mbox);
						imap_setflag_full($mbox,$mboxinfo->Nmsgs,'\Seen \Draft');
						imap_close($mbox);
					}
				elseif (getfolder('Sent')!=false)
					{
						$mbox=imap_open('{'.MAILHOST.'/norsh/notls}'.getfolder('Sent'),$_SESSION['username'],decryptpw($_SESSION['password']));
						imap_append($mbox,'{'.MAILHOST.'}'.getfolder('Sent'),$mail->composemail());
						$mboxinfo=imap_mailboxmsginfo($mbox);
						imap_setflag_full($mbox,$mboxinfo->Nmsgs,'\Seen');
						imap_close($mbox);
					}
			}
		unset($mail);
		for ($x=0;$x<count($attachedfiles);$x++)
			{
				removetempfile($attachedfiles[$x]);
			}
		if (file_exists('mailtemp/'.session_id()))
			{
				removetempdir();
			}
		header('Location:webmail.php?mailbox='.$mailbox.'&subsite=showmails.php');
		exit;
	}
echo '<html>';
echo '<body>';
echo '<form method="post" action="webmail.php?mailbox='.$mailbox.'&amp;subsite=sendmail.php" enctype="multipart/form-data">';
echo gettext('Recipient').':<input type="text" name="mailto" value="'.$mailto.'"><br>';
echo gettext('Subject').':<input type="text" name="subject" value="'.$subject.'"><br>';
echo '<textarea name="message" cols="80" rows="15">'.$message.'</textarea><br>';
for ($attachment=0;$attachment<count($attachedfiles);$attachment++)
	{
		echo '<input type="hidden" name="attachment'.$attachment.'" value="'.$attachedfiles[$attachment].'">';
		echo '<input type="checkbox" name="delattachment'.$attachment.'" value="'.$attachedfiles[$attachment].'">'.$attachedfiles[$attachment].'<br>';
	}
if (count($attachedfiles)>0)
	{
		echo '<input type="submit" name="removeattachment" value="'.gettext('Remove selected attachments').'"><br>';
	}
echo '<input type="file" name="uploadfile">';
echo '<input type="submit" name="attachfile" value="'.gettext('Attach file').'"><br>';
echo '<input type="checkbox" name="savesent" value="savesent" checked>'.gettext("Save copy in sent eMails folder").'<br>';
echo '<input type="submit" name="sendmail" value="'.gettext("Send eMail").'">';
echo '<input type="submit" name="savedraft" value="'.gettext("Save as Draft").'">';
echo '</form>';
echo '</body>';
echo '</html>';
?>
 
Zurück