Sent mails with phpmailer don't go to "Sent" IMAP folder

piernik picture piernik · Dec 19, 2011 · Viewed 15.9k times · Source

in my CRM online system I control ingoing mails with IMAP protocol. Now I'm making sending mails with phpmailer and SMTP protocol. Everything is ok but I have one wierd thing. How to make sent with phpmailer script mails go to "Sent" IMAP folder?

Answer

piernik picture piernik · Dec 23, 2011

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.