Sent mails with phpmailer don't go to “Sent” IMAP folder

不羁岁月 提交于 2019-11-27 09:14:55

There is now a method getSentMIMEMessage in PHPMailer which returns the whole MIME string

$mail = new PHPMailer();
//code to handle phpmailer
$result = $mail->Send();
if ($result) {
  $mail_string = $mail->getSentMIMEMessage();
  imap_append($ImapStream, $folder, $mail_string, "\\Seen");
}

I found easier way to do this. PHPmailer prepares email as string - all You have to do is to put it into right IMAP folder.

I expanded phpmailer class with this code (since vars are protected I can't reach them):

class PHPMailer_mine extends PHPMailer {
public function get_mail_string() {
    return $this->MIMEHeader.$this->MIMEBody;
}}

PHP code:

$mail= new PHPMailer_mine();
//code to handle phpmailer
$result=$mail->Send();
if ($result) {
    $mail_string=$mail->get_mail_string();
    imap_append($ImapStream, $folder, $mail_string, "\\Seen");
}

It works well.

Well, it's pretty difficult, but can be done.

Take a look at the imap-append function.
By being connected to an IMAP stream resource, you can use the imap-append() to append your mails to the Sent folder of your IMAP account.

But reading through the comments will show you that it's a bit tedious to accomplish, but certainly not impossible - you'll probably need to code something on your own, since phpmailer doesn't support this out of the box (and will most likely be too time consuming to implement instead of making something yourself).

  • You need to be relaying your sent mail through the IMAP host
  • The IMAP host needs to support the feature (which very few do)

If either of these two points are not true, the short answer is "You can't". In short, really it's down to the mail provider, not your code.

As much as I hate M$, Exchange is one place where they really have got things right - if you are using an Exchange server, all of this is handled for you.

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