{"record":{"id":"0c1cbed4593f8394","repo":"cakephp/cakephp","slug":"transport-was-not-defined-you-must-set-on-using-settransport","errorCode":null,"errorMessage":"Transport was not defined. You must set on using setTransport() or set `transport` option in your mailer profile.","messagePattern":"Transport was not defined\\. You must set on using setTransport\\(\\) or set `transport` option in your mailer profile\\.","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"src/Mailer/Mailer.php","lineNumber":482,"sourceCode":"    {\n        if (is_string($name)) {\n            $this->transport = TransportFactory::get($name);\n        } else {\n            $this->transport = $name;\n        }\n\n        return $this;\n    }\n\n    /**\n     * Gets the transport.\n     *\n     * @return \\Cake\\Mailer\\AbstractTransport\n     */\n    public function getTransport(): AbstractTransport\n    {\n        if ($this->transport === null) {\n            throw new BadMethodCallException(\n                'Transport was not defined. '\n                . 'You must set on using setTransport() or set `transport` option in your mailer profile.',\n            );\n        }\n\n        return $this->transport;\n    }\n\n    /**\n     * Backup message, renderer, transport instances before an action is run.\n     *\n     * @return void\n     */\n    protected function backup(): void\n    {\n        $this->clonedInstances['message'] = clone $this->message;\n        if ($this->renderer !== null) {\n            $this->clonedInstances['renderer'] = clone $this->renderer;","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Mailer/Mailer.php#L464-L500","documentation":"Mailer::getTransport() returns the configured AbstractTransport and throws BadMethodCallException if no transport was ever set. Sending requires a transport (Smtp, Mail, Debug, etc.) either set explicitly or via the mailer profile.","triggerScenarios":"Calling deliver()/getTransport() on a Mailer whose transport is still null: neither setTransport() was called nor did the profile include a 'transport' key.","commonSituations":"Instantiating a Mailer directly without a profile; a profile array that omits 'transport'; tests constructing Mailer manually; profile loaded but transport name itself unconfigured.","solutions":["Call $mailer->setTransport('default') (or a transport instance) before deliver().","Add 'transport' => 'default' to the email profile passed to setProfile().","Ensure the transport name referenced is itself configured via EmailTransport config.","In tests, set a Debug transport: $mailer->setTransport(new DebugTransport())."],"exampleFix":"// before\n(new MyMailer())->deliver('hi');\n// after\n(new MyMailer())->setTransport('default')->deliver('hi');","handlingStrategy":"validation","validationCode":"$reflection = new \\ReflectionProperty($mailer, 'transport');\n$reflection->setAccessible(true);\nif ($reflection->getValue($mailer) === null) {\n    $mailer->setTransport('default');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $mailer->deliver('message');\n} catch (\\BadMethodCallException $e) {\n    \\Cake\\Log\\Log::error('Mailer has no transport: ' . $e->getMessage());\n}","preventionTips":["Always include 'transport' => 'default' in email profiles","Set a DebugTransport as fallback in test/CI environments","Construct mailers via getMailer() with profiles rather than bare new"],"tags":["email","configuration","missing-transport"],"backgroundTag":"missing-required-config-field","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}