使用SwiftMailer将邮件添加到发送文件夹

7

我正在使用来自swiftmailer.org的PHP SwiftMailer。

一切都运行良好,但我想知道是否有一种方法可以将发送的消息添加到SwiftMailer发送的邮件账户中的已发送文件夹中?

以上是所有内容,祝您拥有愉快的一天。

2个回答

13
根据开发者所说,SwiftMailer不能将邮件复制到已发送文件夹,因为它是邮件发送程序而不是邮箱管理程序。正如在GitHub页面中所提到的:

SwiftMailer是一个用于发送电子邮件的库,而不是管理邮箱的工具。所以,这确实超出了SwiftMailer的范围。

然而,php.net上的某个用户发布了可能适合你的解决方案
  1. 使用SwiftMailer通过PHP发送消息。

$message = Swift_Message::newInstance("Subject goes here");
// (then add from, to, body, attachments etc)
$result = $mailer->send($message);
当您在上述第1步中构建消息时,请将其保存到变量中,如下所示:
$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"); 

8

我曾经遇到过类似的问题,Sutandiono的回答让我走上了正确的方向。但由于完整性以及我在连接Exchange 2007服务器时遇到了其他问题,我想提供一个完整的代码片段来将邮件存储到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

请使用自己的服务器主机名、用户名和密码替换此信息。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接