craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.21k stars 624 forks source link

3.1 beta: Error when saving Email settings with Type:SMTP #3503

Closed ghost closed 5 years ago

ghost commented 5 years ago

Description

When trying to save Email settings with Type:SMTP there is an error:

Argument 1 passed to Craft::parseEnv() must be of the type string, null given, called in ...\vendor\craftcms\cms\src\behaviors\EnvAttributeParserBehavior.php on line 75

Steps to reproduce

  1. In Email settings choose type SMTP (same with gmail)
  2. Save

Additional info

Thanks.

brandonkelly commented 5 years ago

I’m not able to reproduce this, but pretty sure I’ve fixed it for the next release.

ghost commented 5 years ago

@brandonkelly Thanks, after applying this patch manually (beta-2, solo) i could save and successfully deploy again, excerpt of project.yaml:

email:
  fromEmail: admin@craft2.local
  fromName: Craft2
  template: null
  transportSettings:
    encryptionMethod: tls
    host: smtp.mailtrap.io
    password: $SMTP_PASSWORD
    port: $SMTP_PORT
    timeout: '10'
    useAuthentication: '1'
    username: $SMTP_USER
  transportType: craft\mail\transportadapters\Smtp

Two things:

  1. Clicking 'Test' results in:

    Argument 1 passed to Craft::parseEnv() must be of the type string, null given, called in E:\craft\craft4\vendor\craftcms\cms\src\helpers\App.php on line 401

    Line 401 refers to $settings->template, so it is obviously the template:null line above. Same with sending password reset mail.

  2. I could save environment variables in smtp user/port (no autocompletion here?)/password, but when trying to enter $SMTP_HOST (selected from autocomplete) in the host field, it results in

    Argument 1 passed to craft\helpers\StringHelper::ensureRight() must be of the type string, null given, called in E:\craft\craft2\vendor\craftcms\cms\src\behaviors\EnvAttributeParserBehavior.php on line 85

Thanks again for your great work!

brandonkelly commented 5 years ago

Alright, hopefully those will be fixed for you as well now. Still not able to reproduce though. Even if I leave those settings blank, they hit the server as empty strings, not null.

ghost commented 5 years ago

@brandonkelly Yes, that seems to work now. Thanks again.

One last remark: Obviously you can't set the smtp port via an environment variable, which is fine in our current environment using mailtrap.io for testing, but i'm quite sure that will not be always the case.