Sent Mails with PHPmailer Don't Go to "Sent" Imap Folder

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

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

Mail sent with PHP mail are not shown in my mails Sent folder

You should include your code in your question.

This isn't PHPMailer's job, but it's related. Take a look at the end of the gmail example provided with PHPMailer. It includes a section that uploads a sent message to your IMAP folder. The basic idea is that after you've received a successful send() response, get a copy of the message and upload it to your IMAP mailbox:

...
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
//Section 2: IMAP
if (save_mail($mail)) {
echo "Message saved!";
}
}
//Section 2: IMAP
//IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php
//Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
//You can use imap_getmailboxes($imapStream, '/imap/ssl') to get a list of available folders or labels, this can
//be useful if you are trying to get this working on a non-Gmail IMAP server.
function save_mail($mail)
{
//You can change 'Sent Mail' to any other folder or tag
$path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";
//Tell your server to open an IMAP connection using the same username and password as you used for SMTP
$imapStream = imap_open($path, $mail->Username, $mail->Password);
$result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
imap_close($imapStream);
return $result;
}

CodeIgniter uses a wrapper around PHPMailer, but you should be able to get access to the necessary data somehow, and the IMAP code is not specific to PHPMailer.

PHPMailer Class And Gmail: The sent emails not retain in Sent directory in Gmail

This seems to relate to your problem and it seems that they don't get stored when using smtp. However, you could BCC the sending account and just filter those mails in a separate folder.

Bluehost: PHPMailer save sent message in Sent Items

Thanks to Max for the idea of imap_list function.

This gives me the list of a path for my mail directories.


  $host = '{imap.mydomain.com/ssl/novalidate-cert}';

$mail = 'support@mydomain.com';
$pass = 'password';

$mbox = imap_open($host, $mail, $pass, OP_HALFOPEN)
or die("can't connect: " . imap_last_error());

$list = imap_list($mbox, $host, "*");
if (is_array($list)) {
foreach ($list as $val) {
echo imap_utf7_decode($val) . "\n";
}
} else {
echo "imap_list failed: " . imap_last_error() . "\n";
}

imap_close($mbox);

?>

using the {imap.mydomain.com} or {imap.mydomain.com:993/imap/ssl}gives me an error of:

can't connect: Certificate failure for imap.mydomain.com: Server
name does not match certificate: /OU=Domain Control
Validated/OU=Hosted by BlueHost.Com, INC/OU=PositiveSSL
Wildcard/CN=*.bluehost.com

Certificate issue, luckily I found this question and I end up using the following host:

{imap.mydomain.com/ssl/novalidate-cert}

and the path I'm looking to forward the sent mail into sent items is:

{imap.mydomain.com/ssl/novalidate-cert}INBOX.Sent

Store sent mails using PHPMailer into Office365 account

You need to check if the sent folder exist and the correct name, it can have a similar meaning but different spelling.
First, use php_imap to get a list of folders, the one used for storing sent emails can be used with imap_append method



Related Topics



Leave a reply



Submit