Add mail to Send folder with SwiftMailer

ぐ巨炮叔叔 提交于 2019-12-21 03:01:25

问题


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.


回答1:


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:

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



回答2:


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.



来源:https://stackoverflow.com/questions/19497557/add-mail-to-send-folder-with-swiftmailer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!