PHP Doku:: String als Nachricht in einem Postfach ablegen - function.imap-append.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzE-Mail-relevante ErweiterungenIMAP, POP3 and NNTPIMAP Funktionenimap_append

Ein Service von Reinhard Neidl - Webprogrammierung.

IMAP Funktionen

<<imap_alerts

imap_base64>>

imap_append

(PHP 4, PHP 5)

imap_appendString als Nachricht in einem Postfach ablegen

Beschreibung

bool imap_append ( resource $imap_stream , string $mailbox , string $message [, string $options = NULL ] )

Der in message übergebene String wird als Nachricht an das Postfach mailbox angefügt.

Parameter-Liste

imap_stream

Eine von imap_open() zurückgegebene IMAP-Verbindung.

mailbox

Der Name des Postfachs, siehe imap_open() für nähere Informationen.

message

Die anzufügende Nachricht als String

Bei Verbindungen mit dem Cyrus IMAP server ist es zwingend erforderlich "\r\n" als Zeilenende zu benutzen, mit einem einfachen "n" schlägt die Operation fehl.

options

Wenn angegeben werden die in options gesetzten Optionen der Nachricht bei der Anlage gesetzt.

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Beispiele

Beispiel #1 imap_append() Beispiel

<?php
$stream 
imap_open("{imap.example.org}INBOX.Drafts""username""password");

$check imap_check($stream);
echo 
"Msg Count before append: "$check->Nmsgs "\n";

imap_append($stream"{imap.example.org}INBOX.Drafts"
                   
"From: me@example.com\r\n"
                   
"To: you@example.com\r\n"
                   
"Subject: test\r\n"
                   
"\r\n"
                   
"this is a test message, please ignore\r\n"
                   
);

$check imap_check($stream);
echo 
"Msg Count after append : "$check->Nmsgs "\n";

imap_close($stream);
?>


9 BenutzerBeiträge:
- Beiträge aktualisieren...
kaminski at istori dot com
16.08.2010 5:52
The date format string to use when creating $internal_date is 'd-M-Y H:i:s O'.
chris at sma-sportsmgmt dot com
8.02.2008 8:06
I spend most of today refining the example to make it work properly when saving to the Inbox.Sent folder.

The append command now looks like:

    $return = imap_append($stream,$mailbox_addr
                       , "From: $fromReply\r\n"
                       . "To: $to\r\n"
                       . "Subject: $subject\r\n"
                       . "Date: $now  \r\n"
              . "X-Mailer: Cmail_v2.0 \r\n"
                       . "X-Originating-IP: $ip_addr \r\n"
                       . "MIME-Version: 1 \r\n"
                       . "Content-Type: text/html;\r\n\tcharset=\"ISO-8859-1\"\r\n"
                       . "Content-Transfer-Encoding: 8bit \r\n"
                       . "\r\n\r\n"
                       . "$wk_msg\r\n"
                       );

This inserts the current date into the email and lets it support html content. The one thing that I haven't got working yet is including attachments. I presumably have to make the boundaries and attachment content part of the message body.

Chris
jille at DIESPAMMERShexon dot cx
3.05.2007 16:36
The last argument, $options, are flags like for use with imap_setflag_full.
It took a while before I found out
svicentemolina at gmail dot com
17.01.2007 16:57
I have used this function to copy all the emails of one account from one server to another. The problem was that this function don't copy the original receiving date for each message.
To add a fifth field to provide the date, I have made some changes at some php source files following the steps described in http://www.zend.com/lists/php-dev/200303/msg00843.html and it has worked fine.
The correct date format is the returned by the function mail_date in c-client/mail.c source file, for instance: "17-Jan-2007 10:00:01 +0100"
bithive
24.06.2003 0:26
The parameter description is misleading.  You can pass a string of flags such as '\Seen' [see imap_setflag_full()] as the last argument.  In the other imap functions, 'options' seems to usually refer to a bitmask, not message flags.
michel dot jansens at ulb dot ac dot be
29.04.2003 16:29
I use imap_append() to decode message/rfc822 attachments type(embedded emails):

$attachment = imap_fetchbody($mbox,$mailuid,$atpos,FT_UID);
$attachment = imap_base64($attachment);
$res =  imap_append($mbox,mboxspec("INBOX"),$attachment);
//the embedded email is now a normal mail in my INBOX
bluebiru78 at hotmail dot com
12.06.2002 9:24
i used imap_append to copy any composed message into INBOX.Sent folder..

$app = imap_append($stream,"{" . $connectstring . "}INBOX.Sent","$header\r\n" ."$mbody\r\n");

if (!$app) {
 error("Email copying to Sent folder FAILED!");
}
owain at vaughan dot com
1.08.2001 15:49
With SIMS IMAP server you also need to use \r\n as a line terminator, otherwise you will be able to add all the header lines correctly, but the body of the message will not be saved.<br>
You can use \n by itself for each header line, but when creating the blank line between the headers and the body you must use \r\n\r\n
jesper at angelo dot dk
14.09.1999 18:13
Please observe that imap_append() do not support NNTP posting. Use fsockopen() instead, and do the work yourself.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)