繁体   English   中英

通过PHP邮件发送的邮件未显示在我的邮件“已发送”文件夹中

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

我正在将电子邮件从我的Webmail帐户发送到任何电子邮件地址。

邮件发送成功,但是如何在我的Webmail帐户的sendmail文件夹中保存此邮件。

我使用codeigniter电子邮件发送功能。

您应该在问题中包含代码。

这不是PHPMailer的工作,而是相关的。 看一下PHPMailer提供的gmail示例的结尾 它包括一个部分,该部分将已发送的邮件上载到您的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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM