barbushin / php-imap

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
MIT License
1.67k stars 460 forks source link

[BUG] Uncaught Error: Call to undefined method PhpImap\IncomingMail::hasAttachments() #695

Open gdemir opened 1 year ago

gdemir commented 1 year ago

The used code:

// composer packages load
require_once "vendor/autoload.php";
use PhpImap\Exceptions\ConnectionException;
use PhpImap\Mailbox;
$mailbox = new Mailbox(
        '{imap.yandex.com.tr:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
        'gdemir3327@yandex.com', // Username for the before configured mailbox
        '********', // Password for the before configured username
    __DIR__ . '/upload/', // Directory, where attachments will be saved (optional)
        'UTF-8', // Server encoding (optional)
         true, // Trim leading/ending whitespaces of IMAP path (optional)
         false // Attachment filename mode (optional; false = random filename; true = original filename)
     );
    echo 'mail has attachments? ';
    if ($email->hasAttachments()) {
        echo "Yes\n";
    } else {
        echo "No\n";
    }

Screenshots / Outputs Fatal error: Uncaught Error: Call to undefined method PhpImap\IncomingMail::hasAttachments() in /var/www/vhosts/httpdocs/ir/index.php:53 Stack trace: #0 {main} thrown in /var/www/vhosts//httpdocs/ir/index.php on line 53

teamcoltra commented 9 months ago

Popping in to say I also had this. I'm not dealing with attachments so it doesn't matter to me but it was in the demo code.

teamcoltra commented 9 months ago

Found the issue: use composer require php-imap/php-imap:dev-master

as the main one is super old and out of date.