Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : IMAP, POP3 and NNTP Functions : imap_append

imap_append

Append a string message to a specified mailbox (PHP 4, PHP 5)
bool imap_append ( resource imap_stream, string mailbox, string message [, string options] )

Example 1044. imap_append() example

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

Code Examples / Notes » imap_append

owain

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


bithive

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.

jille

The last argument, $options, are flags like for use with imap_setflag_full.
It took a while before I found out


jesper

Please observe that imap_append() do not support NNTP posting. Use fsockopen() instead, and do the work yourself.

bluebiru78

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!");
}


michel dot jansens

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


svicentemolina

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"


Change Language


Follow Navioo On Twitter
imap_8bit
imap_alerts
imap_append
imap_base64
imap_binary
imap_body
imap_bodystruct
imap_check
imap_clearflag_full
imap_close
imap_createmailbox
imap_delete
imap_deletemailbox
imap_errors
imap_expunge
imap_fetch_overview
imap_fetchbody
imap_fetchheader
imap_fetchstructure
imap_get_quota
imap_get_quotaroot
imap_getacl
imap_getmailboxes
imap_getsubscribed
imap_header
imap_headerinfo
imap_headers
imap_last_error
imap_list
imap_listmailbox
imap_listscan
imap_listsubscribed
imap_lsub
imap_mail_compose
imap_mail_copy
imap_mail_move
imap_mail
imap_mailboxmsginfo
imap_mime_header_decode
imap_msgno
imap_num_msg
imap_num_recent
imap_open
imap_ping
imap_qprint
imap_renamemailbox
imap_reopen
imap_rfc822_parse_adrlist
imap_rfc822_parse_headers
imap_rfc822_write_address
imap_savebody
imap_scanmailbox
imap_search
imap_set_quota
imap_setacl
imap_setflag_full
imap_sort
imap_status
imap_subscribe
imap_thread
imap_timeout
imap_uid
imap_undelete
imap_unsubscribe
imap_utf7_decode
imap_utf7_encode
imap_utf8
eXTReMe Tracker