imap_append
(PHP 4, PHP 5)
imap_append — Append a string message to a specified mailbox
Description
$imap_stream
, string $mailbox
, string $message
[, string $options
= NULL
[, string $internal_date
= NULL
]] )
Appends a string message
to the specified mailbox
.
Parameters
-
imap_stream
-
An IMAP stream returned by imap_open().
-
mailbox
-
The mailbox name, see imap_open() for more information
-
message
-
The message to be append, as a string
When talking to the Cyrus IMAP server, you must use "\r\n" as your end-of-line terminator instead of "\n" or the operation will fail
-
options
-
If provided, the
options
will also be written to themailbox
-
internal_date
-
If this parameter is set, it will set the INTERNALDATE on the appended message. The parameter should be a date string that conforms to the rfc2060 specifications for a date_time value.
Return Values
Returns TRUE
on success or FALSE
on failure.
Changelog
Version | Description |
---|---|
5.3.2 | Added INTERNALDATE support to imap_append. |
Examples
Example #1 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);
?>
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с почтой
- IMAP, POP3 и NNTP
- imap_8bit
- imap_alerts
- imap_append
- imap_base64
- imap_binary
- imap_body
- imap_bodystruct
- imap_check
- imap_clearflag_full
- imap_close
- imap_create
- imap_createmailbox
- imap_delete
- imap_deletemailbox
- imap_errors
- imap_expunge
- imap_fetch_overview
- imap_fetchbody
- imap_fetchheader
- imap_fetchmime
- imap_fetchstructure
- imap_fetchtext
- imap_gc
- 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_rename
- imap_renamemailbox
- imap_reopen
- imap_rfc822_parse_adrlist
- imap_rfc822_parse_headers
- imap_rfc822_write_address
- imap_savebody
- imap_scan
- 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
Коментарии
The date format string to use when creating $internal_date is 'd-M-Y H:i:s O'.
Hi,
As we have been struggling with this for some time I wanted to share how we got imap_append working properly with all MIME parts including attachments. If you are sending email and also wish to append the sent message to the Sent Items folder, I cannot think of an easier way to do this, as follows:
1) Use SwiftMailer to send the message via PHP.
$message = Swift_Message::newInstance("Subject goes here");
(then add from, to, body, attachments etc)
$result = $mailer->send($message);
2) When you construct the message in step 1) above save it to a variable as follows:
$msg = $message->toString(); (this creates the full MIME message required for imap_append()!! After this you can call imap_append like this:
imap_append($imap_conn,$mail_box,$msg."\r\n","\\Seen");
I hope this helps the readers, and prevents saves people from doing what we started doing - hand crafting the MIME messages :-0
You can use PHPMailer ( https://github.com/PHPMailer/PHPMailer/ ) with imap.
<?php
// after creating content of mail you have to run preSend() - part of send() method
$mail->send();
// and you can get whole raw message with getSentMIMEMessage() method
imap_append($imap, $mailserver.'INBOX.Sent',$mail->getSentMIMEMessage(), "\\Seen");