I'm using SwiftMailer for PHP from swiftmailer.org
Everything works well but I wonder if there is a way to add the sent message into the sent folder from the mail account that SwiftMailer is sending from?
That's all, have a nice day.
According to the developer, swiftmailer cannot copy to Sent folder because it is a mail sender and not mailbox manager.
As mentioned on the github page:
Swiftmailer is a library to send emails, not to manage mailboxes. So, this is indeed out of the scope of Swiftmailer.
However, someone from php.net posted a solution that might work for you:
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);
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've had similar problem and Sutandiono's answer got me into right direction. However because of completeness and as I had additional problem connecting to an Exchange 2007 server, I wanted to provide a complete snippet for storing message to Sent folder on IMAP:
$msg = $message->toString();
// $message is instance of Swift_Message from SwiftMailer
$stream = imap_open("{mail.XXXXX.org/imap/ssl/novalidate-cert}", "username", "password", null, 1, array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));
// connect to IMAP SSL (port 993) without Kerberos and no certificate validation
imap_append($stream,"{mail.XXXXX.org/imap/ssl/novalidate-cert}Sent Items",$msg."\r\n","\\Seen");
// Saves message to Sent folder and marks it as read
imap_close($stream);
// Close connection to the server when you're done
Replace server hostname, username and password with your own information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With