501 Syntactically invalid HELO argument(s)

Hii there,

I’m trying to send an email through the CakePHP (3.9) SMTP class, however, this fails with an error (see title).
When I dd() my email, this is the output (obviously I’ve blurred some sensitive information):


this is the code I’m using:

  namespace Admiral\Admiral;

  use Cake\Mailer\Email as CakeMail;
  use Admiral\Admiral\Settings;
  use Cake\Core\Configure;

  class Email {
    private $email = [];
    private $cakeMail;

    public function __construct() {
      $this->cakeMail = new CakeMail();
      $this->email['transport'] = 'default';
      $this->email['template'] = 'default';
      $this->email['from'] = $this->cakeMail->getConfigTransport('default')['from'];

    public function set(string $option = '', $value) {
      $this->email[$option] = $value;

    public function get(string $option = null) {
      if(!$option) {
        return $this->email;

      return $this->email[$option];

    public function send() {
      // Create the mail
      $this->cakeMail->setFrom($this->email['from']['mail'], $this->email['from']['name']);

      if(!empty($this->email['subject'])) $this->cakeMail->setSubject($this->email['subject']);
      if(!empty($this->email['replyTo'])) $this->cakeMail->setReplyTo($this->email['replyTo']);
      if(!empty($this->email['template'])) $this->cakeMail->viewBuilder()->setTemplate($this->email['template']);
      if(!empty($this->email['format'])) $this->cakeMail->emailFormat($this->email['format']);
      if(!empty($this->email['viewVars'])) $this->cakeMail->setViewVars($this->email['viewVars']);
        'transport' => 'default',
        'from' => $this->email['from']['mail']

      // Send the email and return the result
      try {
        return $this->cakeMail->send();
      } catch (\Exception $e) {
        return $e;

Which gets called using this code:

// Build our email
$email = new Email();
$email->set('to', $user->email);
$email->set('subject', 'Your login code for ' . env('APP_NAME'));
$email->set('viewVars', [
  'code' => $code,

// Send the email
$status = $email->send();

Even using a smaller piece of code doesn’t seem to work (same error):

$email = new \Cake\Mailer\Email('default');
$email->from(['example@finlaydag33k.nl' => 'FinlayDaG33k'])
      ->subject('Test Email')
      ->send('Test Email message');

// Send the email
$status = $email->send();

Port 25 is not generally used for authenticated sending. 465 and 587 are much more common. Perhaps that’s it? Whatever details you use for sending email through this account via Outlook or Thunderbird or whatever should work here.

I have tried using the same SMTP host, credentials, ports etc. as I use in Thunderbird but to no avail :\

After checking the stack trace a bit more, I noticed the HELO {$host} didn’t pass a host.

So, I went looking into the source-code guided by said stacktrace and found that the code checks whether the is set ("isset()") rather than whether it’s empty or, in my case, “null”.
This caused the HELO to be invalid, and as such, caused the error.

After changing this to localhost in my app.php, the mail send just fine.

I’ll be opening an issue to the CakePHP repo tomorrow (iiiiif I don’t forget) about this to discuss further whether this was intended behaviour and whether it needs fixing.