Save email to SENT, IMAP folder

0

I am trying to save emails sent by PhpMailer in the "Sent" folder, so that whoever accesses the email will see what was sent by the system.

I can save the Inbox folder with the following code:

$mailbox = "{".$mail->Host.":143/novalidate-cert}Inbox";
$imapStream = imap_open($mailbox, $mail->Username, $mail->Password);
imap_append($imapStream, $mailbox, $mail->getSentMIMEMessage());
imap_close($imapStream);

But if I swap Inbox with Sent , nothing happens. How to make it work?

    
asked by anonymous 12.11.2018 / 14:13

1 answer

0

With doubt if the folder really is Sent .
I used IMAP to list the folders and found that the folder is INBOX.Sent .

I used the following code to list folders:

$mailbox = "{".$mail->Host.":143/imap/novalidate-cert}";
$imapStream = imap_open($mailbox, $mail->Username, $mail->Password);
$mailboxes = imap_list($imapStream, $mailbox, '*');
echo "<pre>";
print_r($mailboxes);

And the code below to save a copy of the email in "Sent":

$mailbox = "{".$mail->Host.":143/imap/novalidate-cert}INBOX.Sent";
$imapStream = imap_open($mailbox, $mail->Username, $mail->Password);
imap_append($imapStream, $mailbox, $mail->getSentMIMEMessage(), "\Seen");
imap_close($imapStream);

As the function does not come the recipient made the following adjustment:

$mailbox = "{".$mail->Host.":143/imap/novalidate-cert}INBOX.Sent";
$imapStream = imap_open($mailbox, $mail->Username, $mail->Password);
imap_append($imapStream, $mailbox, "To: ".$destinatario."\r\n".$mail->getSentMIMEMessage(), "\Seen");
imap_close($imapStream);
    
12.11.2018 / 14:40