cakephp/cakephp · error · InvalidArgumentException

Transfer encoding not available. Can be

Error message

Transfer encoding not available. Can be : %s.

What it means

Message::setTransferEncoding() validates the given encoding against Message::$transferEncodingAvailable (e.g. 7bit, 8bit, quoted-printable, base64) and throws InvalidArgumentException for anything outside that list. Transfer encoding controls how the email body is encoded in transit.

Solutions

  1. Use one of the supported values: '7bit', '8bit', 'quoted-printable', or 'base64'.
  2. Pass null to reset transfer encoding to default instead of an invalid value.
  3. If the value comes from config, whitelist/validate it before passing.

Example fix

// before
$message->setTransferEncoding('utf-8');
// after
$message->setTransferEncoding('base64');
Defensive patterns

Strategy: validation

Validate before calling

$allowed = ['7bit', '8bit', 'quoted-printable', 'base64'];
if ($encoding !== null && !in_array(strtolower($encoding), $allowed, true)) {
    throw new \InvalidArgumentException("Unsupported transfer encoding: $encoding");
}

Type guard

function isValidTransferEncoding(?string $encoding): bool {
    return $encoding === null || in_array(strtolower($encoding), ['7bit', '8bit', 'quoted-printable', 'base64'], true);
}

Try / catch

try {
    $message->setTransferEncoding($encoding);
} catch (\InvalidArgumentException $e) {
    $message->setTransferEncoding(null); // default
}

Prevention

When it happens

Trigger: setTransferEncoding('gzip'), setTransferEncoding('Base64') casing is fine (lowercased) but unknown values like 'binary-enc' or empty-but-non-null strings throw.

Common situations: Confusing Content-Transfer-Encoding values with character encodings ('utf-8'); copying encoding names from another mail library; passing user-supplied encoding config from a settings file.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of cakephp/cakephp@1128eba9b0 (2026-09-12). Data as JSON: /api/errors/23381058ded81570. Report an issue: GitHub.

Appendix: source

Thrown at src/Mailer/Message.php:643

     */
    public function getHeaderCharset(): string
    {
        return $this->headerCharset ?: $this->charset;
    }

    /**
     * TransferEncoding setter.
     *
     * @param string|null $encoding Encoding set.
     * @return $this
     * @throws \InvalidArgumentException
     */
    public function setTransferEncoding(?string $encoding)
    {
        if ($encoding !== null) {
            $encoding = strtolower($encoding);
            if (!in_array($encoding, $this->transferEncodingAvailable, true)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Transfer encoding not available. Can be : %s.',
                        implode(', ', $this->transferEncodingAvailable),
                    ),
                );
            }
        }

        $this->transferEncoding = $encoding;

        return $this;
    }

    /**
     * TransferEncoding getter.
     *
     * @return string|null Encoding
     */

View on GitHub (pinned to 1128eba9b0)