【问题标题】:Mail sent with PHP mail are not shown in my mails Sent folder使用 PHP 邮件发送的邮件未显示在我的邮件已发送文件夹中
【发布时间】:2018-05-08 09:41:15
【问题描述】:

我正在从我的网络邮件帐户向任何电子邮件地址发送电子邮件。

邮件发送成功,但是我怎样才能将这些邮件放在我的网络邮件帐户发送文件夹中。

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

【问题讨论】:

    标签: php smtp phpmailer imap codeigniter-3


    【解决方案1】:

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

    这不是 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。

    【讨论】:

    • 感谢您的回复,imap_append 非常适合我
    • 请注意:Gmail,具体而言,如果通过 smtp.gmail.com 发送,将自动将副本放入“已发送”文件夹。这是非标准行为。
    • @user5677872 - 如果您喜欢我的回答并解决了您的问题,请将其标记为正确答案。
    • 有人知道如何找到不同电子邮件帐户的路径“{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail”吗? (我在我的专用服务器上使用 blacknight)
    猜你喜欢
    • 2016-10-02
    • 2020-01-30
    • 1970-01-01
    • 2013-08-26
    • 2021-07-08
    • 2020-04-19
    • 1970-01-01
    • 2014-04-14
    • 1970-01-01
    相关资源
    最近更新 更多