我试图计算所有电子邮件和电子邮件,但我的脚本只计算收件箱中的邮件,
任何人都知道如何计算来自邮件帐户的所有电子邮件,包括已发送,垃圾邮件,已删除等
$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);
答案 0 :(得分:0)
首先使用imap_list列出所有可用文件夹。 然后$ conn_str =" {"。$ mailcnf。"} $ mailbox"而不是邮箱 imap_num_msg应返回当前邮箱中的电子邮件数
答案 1 :(得分: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);
?>