note 130006 added to function.imap-append

From: Date: Sun, 02 Feb 2025 05:47:58 +0000
Subject: note 130006 added to function.imap-append
Groups: php.notes 
Request: Send a blank email to php-notes+get-221826@lists.php.net to get a copy of this message
This function is how you take a sent message in your mail shell and place a copy of it in the remote mail server's sent folder. It is however not intuitive and I struggled for a couple hours so I'm placing these notes here to spare others the aggravation. Some of the errors I encountered: - Can't append to mailbox with such a name - Internal date not correctly formatted The second/folder parameter is not the string you might think it is (e.g. "Sent", "Inbox.Sent", etc). It is the connection information used by imap_open() which doesn't make sense as the connection is already open! Whatever, here is a basic example addressing those three errors: <?php $server = '{mail.example.com:993/ssl/imap}INBOX.Sent'; $mail_connection_folder = imap_open($server, $user, $pass); if ($mail_connection) { $result = imap_append($mail_connection, $server, $message_string_raw, '\\Seen', date('d-M-Y H:i:s O')); } ?> I had been using the PHP Pear Mail extension which did a fantastic job with DMARC, SPF, DKIM, etc. However it's not well maintained and I couldn't figure out if it returns the email message string. The PHPMailer library (https://github.com/PHPMailer/PHPMailer) does return the message string: <?php //Skip to key parts: $result = $mail->send(); if ($result) { $message_string_raw = $mail->getSentMIMEMessage(); } else {/*error handling*/} ?> Hopefully this will spare some folks a lot of aggravation. ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.84.18 (proxied: 149.102.242.23) ---- Manual Page -- https://php.net/manual/en/function.imap-append.php Edit -- https://main.php.net/note/edit/130006 Del: integrated -- https://main.php.net/note/delete/130006/integrated Del: useless -- https://main.php.net/note/delete/130006/useless Del: bad code -- https://main.php.net/note/delete/130006/bad+code Del: spam -- https://main.php.net/note/delete/130006/spam Del: non-english -- https://main.php.net/note/delete/130006/non-english Del: in docs -- https://main.php.net/note/delete/130006/in+docs Del: other reasons-- https://main.php.net/note/delete/130006 Reject -- https://main.php.net/note/reject/130006 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221826) next »