cakephp-error-email icon indicating copy to clipboard operation
cakephp-error-email copied to clipboard

Error after updating to CakePHP 3.8

Open mckrti opened this issue 7 years ago • 6 comments

I am getting the following error:

Fatal error: Uncaught InvalidArgumentException: Unknown email configuration "default". in /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php:2243 Stack trace: #0 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php(2083): Cake\Mailer\Email->_applyConfig(NULL) #1 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php(362): Cake\Mailer\Email->setProfile('default') #2 /var/www/x/cakephp/vendor/ebrigham1/cakephp-error-email/src/Traits/EmailThrowableTrait.php(51): Cake\Mailer\Email->__construct('default') #3 /var/www/x/cakephp/vendor/ebrigham1/cakephp-error-email/src/Traits/EmailThrowableTrait.php(37): ErrorEmail\Error\ErrorHandler->_getMailer() #4 /var/www/x/cakephp/vendor/ebrigham1/cakephp-error-email/src/Error/ErrorHandler.php(80): ErrorEmail\Error\ErrorHandler->emailThrowable(Object(Error)) #5 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php(176): ErrorEmail\Error\ErrorHandler->handleException( in /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php on line 2243

Fatal error: Uncaught InvalidArgumentException: Unknown email configuration "default". in /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php:2243 Stack trace: #0 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php(2083): Cake\Mailer\Email->_applyConfig(NULL) #1 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php(362): Cake\Mailer\Email->setProfile('default') #2 /var/www/x/cakephp/vendor/ebrigham1/cakephp-error-email/src/Traits/EmailThrowableTrait.php(51): Cake\Mailer\Email->__construct('default') #3 /var/www/x/cakephp/vendor/ebrigham1/cakephp-error-email/src/Traits/EmailThrowableTrait.php(37): ErrorEmail\Error\ErrorHandler->_getMailer() #4 /var/www/x/cakephp/vendor/ebrigham1/cakephp-error-email/src/Error/ErrorHandler.php(80): ErrorEmail\Error\ErrorHandler->emailThrowable(Object(Cake\Error\FatalErrorException)) #5 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php(230): ErrorEmail\Error\Error in /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php on line 2243

mckrti avatar Nov 06 '19 19:11 mckrti

Hi @mckrti it looks to me like maybe you don't have the default email delivery profile. In your config/app.php do you still have an email delivery profile called default?

It goes with this config value:

emailDeliveryProfile (string) - The email delivery profile (defined in config/app.php under the Email key) to use "default" is the default

If you don't have the default key you'll have to update your emailDeliveryProfile to whatever email delivery profile you want to use.

Let me know if this helps.

ebrigham1 avatar Nov 06 '19 19:11 ebrigham1

Hi,

I do have the delivery profile in app.php

'EmailTransport' => [ 'default' => [ 'className' => 'Smtp', //'className' => 'Mail', // The following keys are used in SMTP transports 'host' => 'xxxx', 'port' => 111, 'timeout' => 30, 'username' => 'xxxxxx', 'password' => 'xxxxx', 'client' => null, 'tls' => true, 'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null), ], ],

/**
 * Email delivery profiles
 *
 * Delivery profiles allow you to predefine various properties about email
 * messages from your application and give the settings a name. This saves
 * duplication across your application and makes maintenance and development
 * easier. Each profile accepts a number of keys. See `Cake\Mailer\Email`
 * for more information.
 */
'Email' => [
    'default' => [
        'transport' => 'default',
        'from' => 'you@localhost',
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    ],
],

mckrti avatar Nov 06 '19 20:11 mckrti

Hi @mckrti I didn't have time to look further into this last night, sorry, I'm hoping to have some time tonight to try to just install the plugin on a fresh version of cake 3.8.x. I would suggest you try the same as a next step if nothing obvious is popping out.

The reason I suggested you might not have a default config was following the stack trace you posted:

Fatal error: Uncaught InvalidArgumentException: Unknown email configuration "default". in /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php:2243
Stack trace:
#0 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php(2083): Cake\Mailer\Email->_applyConfig(NULL)
#1 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php(362): Cake\Mailer\Email->setProfile('default')
#2 /var/www/x/cakephp/vendor/ebrigham1/cakephp-error-email/src/Traits/EmailThrowableTrait.php(51): Cake\Mailer\Email->__construct('default')
#3 /var/www/x/cakephp/vendor/ebrigham1/cakephp-error-email/src/Traits/EmailThrowableTrait.php(37): ErrorEmail\Error\ErrorHandler->_getMailer()
#4 /var/www/x/cakephp/vendor/ebrigham1/cakephp-error-email/src/Error/ErrorHandler.php(80): ErrorEmail\Error\ErrorHandler->emailThrowable(Object(Error))
#5 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php(176): ErrorEmail\Error\ErrorHandler->handleException( in /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php on line 2243

The relevant ones are

  1. #2 /var/www/x/cakephp/vendor/ebrigham1/cakephp-error-email/src/Traits/EmailThrowableTrait.php(51): Cake\Mailer\Email->__construct('default')
  2. #1 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php(362): Cake\Mailer\Email->setProfile('default')
  3. #0 /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php(2083): Cake\Mailer\Email->_applyConfig(NULL)
  4. Fatal error: Uncaught InvalidArgumentException: Unknown email configuration "default". in /var/www/x/cakephp/vendor/cakephp/cakephp/src/Mailer/Email.php:2243

The two things I'm unsure about are 3 and 4. 3 Appears to say you're passing null in as the parameter for _applyConfig which doesn't seem to make sense since in 4 you're passing the is_string check and we see 'default' being passed along through the rest of the stack trace. If you are passing the is_string check with 'default' then the only way to have that exception thrown would be if your config wasn't found from static::getConfig. Is it possible your config isn't loaded yet at the time this error is happening?

ebrigham1 avatar Nov 07 '19 11:11 ebrigham1

I checked and I do have these lines above in the Email.php file:

public function __construct($config = null)
{
    $this->_appCharset = Configure::read('App.encoding');
    if ($this->_appCharset !== null) {
        $this->charset = $this->_appCharset;
    }
    $this->_domain = preg_replace('/\:\d+$/', '', env('HTTP_HOST'));
    if (empty($this->_domain)) {
        $this->_domain = php_uname('n');
    }

    $this->viewBuilder()
        ->setClassName('Cake\View\View')
        ->setTemplate('')
        ->setLayout('default')
        ->setHelpers(['Html']);

    if ($config === null) {
        $config = static::getConfig('default');
    }
    if ($config) {
        $this->setProfile($config);
    }
    if (empty($this->headerCharset)) {
        $this->headerCharset = $this->charset;
    }
}

mckrti avatar Nov 07 '19 17:11 mckrti

Hi @mckrti

So I did some more testing and got a fresh install of cakephp 3.8.6. I installed the plugin and generated an error and everything seemed to work as expected. Have you been able to test with a fresh install yet? I still think your config isn't being loaded. Perhaps the error you're experiencing is happening before the app loads the config somewhere in the bootstrapping process? Can you find the original error that is triggering this error in the plugin code and fix see what it is? If its happening before config is loaded I believe the plugin will have trouble just because emailing depends being able to access config values.

ebrigham1 avatar Nov 10 '19 14:11 ebrigham1

Hi @mckrti I haven't heard from you in a while, I'm going to guess this isn't still and issue but if it is please feel free to re-open this issue and we can discuss further.

ebrigham1 avatar Jan 26 '20 19:01 ebrigham1