1

我正在尝试计算来自和电子邮件的所有电子邮件,但我的脚本只计算来自收件箱的邮件,

任何人都知道如何计算来自邮件帐户的所有电子邮件,包括已发送、垃圾邮件、已删除等

$mailcnf = "mail.office365.com:993/imap/ssl/novalidate-cert";
$conn_str = "{".$mailcnf."}INBOX";


$username = 'test3@sjnewman.co.uk';
$password = 'Woju6532';
$imap = imap_open($conn_str,$username,$password) or die('Cannot connect to Server: ' . imap_last_error());

echo $message_count = imap_num_msg($imap);
4

2 回答 2

0

您可以遍历每个文件夹并使用imap_status()来计算每个文件夹中的电子邮件数量。这是一个例子:

<?php
$username = 'mail@example.com';
$password = 'password123';

// Define the connection string:
$server = '{server.example.net:993/ssl}';

// Connect to the server:
$connection = imap_open($server, $username, $password);

// List the mailboxes:
$mailboxes = imap_list($connection, $server, '*');

// Loop through the mailboxes:
foreach($mailboxes as $mailbox) {
 $status = imap_status($connection, "$mailbox", SA_ALL);
    if ($status) {
      echo "Mailbox: $mailbox\t\tMessages: " . $status->messages . "\n";
    } else {
        echo "imap_status failed: " . imap_last_error() . "\n";
    }
}

// Close the connection:
imap_close($connection);
?>
于 2018-08-10T11:57:14.670 回答
0

首先使用 imap_list 列出所有可用的文件夹。那么 $conn_str = "{".$mailcnf."}$mailbox" 而不是邮箱 imap_num_msg 应该返回当前邮箱中的电子邮件数量

于 2016-03-22T10:49:46.213 回答