【发布时间】:2018-05-08 09:41:15
【问题描述】:
我正在从我的网络邮件帐户向任何电子邮件地址发送电子邮件。
邮件发送成功,但是我怎样才能将这些邮件放在我的网络邮件帐户发送文件夹中。
我使用 codeigniter 电子邮件发送功能。
【问题讨论】:
标签: php smtp phpmailer imap codeigniter-3
我正在从我的网络邮件帐户向任何电子邮件地址发送电子邮件。
邮件发送成功,但是我怎样才能将这些邮件放在我的网络邮件帐户发送文件夹中。
我使用 codeigniter 电子邮件发送功能。
【问题讨论】:
标签: php smtp phpmailer imap codeigniter-3
您应该在问题中包含您的代码。
这不是 PHPMailer 的工作,但它是相关的。看看the end of the gmail example provided with PHPMailer。它包括一个将发送的消息上传到 IMAP 文件夹的部分。基本思路是,在您收到成功的send() 响应后,获取邮件副本并将其上传到您的 IMAP 邮箱:
...
//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 使用 PHPMailer 的包装器,但您应该能够以某种方式访问必要的数据,并且 IMAP 代码并非特定于 PHPMailer。
【讨论】: