Sending emails causes an exception

After long time I tried to resend an invitation email to one user on my phabricator instance. But he received nothing. Thus I tried to run the “./bin/mail send-test”, but get an exception

[2021-09-27 22:13:35] EXCEPTION: (Error) Call to undefined function each() at [<phabricator>/externals/phpmailer/class.smtp.php:388]
arcanist(head=stable, ref.master=eb732555a71a, ref.stable=4f70fcffa8a5), phabricator(head=stable, ref.master=979187132d7b, ref.stable=193798385bd3)
  #0 SMTP::Data(string) called at [<phabricator>/externals/phpmailer/class.phpmailer.php:740]
  #1 PHPMailer::SmtpSend(string, string) called at [<phabricator>/externals/phpmailer/class.phpmailer.php:576]
  #2 PHPMailer::Send() called at [<phabricator>/src/applications/metamta/adapter/PhabricatorMailSMTPAdapter.php:155]
  #3 PhabricatorMailSMTPAdapter::sendMessage(PhabricatorMailEmailMessage) called at [<phabricator>/src/applications/metamta/storage/PhabricatorMetaMTAMail.php:750]
  #4 PhabricatorMetaMTAMail::sendWithMailers(array) called at [<phabricator>/src/applications/metamta/storage/PhabricatorMetaMTAMail.php:555]
  #5 PhabricatorMetaMTAMail::sendNow() called at [<phabricator>/src/applications/metamta/PhabricatorMetaMTAWorker.php:22]
  #6 PhabricatorMetaMTAWorker::doWork() called at [<phabricator>/src/infrastructure/daemon/workers/PhabricatorWorker.php:124]
  #7 PhabricatorWorker::executeTask() called at [<phabricator>/src/infrastructure/daemon/workers/PhabricatorWorker.php:166]
  #8 PhabricatorWorker::scheduleTask(string, integer, array) called at [<phabricator>/src/applications/metamta/storage/PhabricatorMetaMTAMail.php:525]
  #9 PhabricatorMetaMTAMail::save() called at [<phabricator>/src/applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php:228]
  #10 PhabricatorMailManagementSendTestWorkflow::execute(PhutilArgumentParser) called at [<arcanist>/src/parser/argument/PhutilArgumentParser.php:492]
  #11 PhutilArgumentParser::parseWorkflowsFull(array) called at [<arcanist>/src/parser/argument/PhutilArgumentParser.php:377]
  #12 PhutilArgumentParser::parseWorkflows(array) called at [<phabricator>/scripts/mail/manage_mail.php:21]```

The email is then listed on ./bin/mail list-outbound as Queued, but apparently never leaves the queue.

I tested in on the latest stable (I did’t the update just today), but I don’t know when the problem appeared, because I haven’t added any new user from very long time.

Well, looks like this is an issue with PHP 8: the each() function was removed PHP: each - Manual.

The built-in SMPT support is using PHPMailer, which isn’t very good - T12404 talks about replacing it.

The simplest work-around is probably to either replace the mailers with one of the more stable ones (◉ Configuring Outbound Email - but not sendmail which also uses each()), or roll down to PHP 7.

Indeed, falling back to php7 worked, thank you!