Save email to SENT, IMAP folder

Asked

Viewed 225 times

0

I am trying to save the emails sent by Phpmailer in the "Sent" folder, so that those who access the email see what was sent by the system.

I can save to the folder Inbox 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 change Inbox for Sent, nothing happens.
How to make it work ?

1 answer

1


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

I used the code below to list the 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 in the function does not come the recipient made the following suitability:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.