我正在尝试将 swiftmailer 配置为使用 gmail 从我的 symfony4 应用程序、本地环境(Wamp、win10)发送电子邮件。
当我在 config/packages/swiftmailer.yaml 文件中添加我的所有参数时,配置运行良好,但是一旦我尝试使用 .env 文件变量,它就不起作用并且我收到此错误:
14:01:11 DEBUG [php] Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
[
"exception" => Symfony\Component\Debug\Exception\SilencedErrorContext {
+count: 1
-severity: E_WARNING
trace: {
C:\wamp\www\crm-granger\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php:267 { …}
C:\wamp\www\crm-granger\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php:58 { …}
}
}
]
14:01:11 DEBUG [php] Warning: stream_socket_client(): Failed to enable crypto
14:01:11 DEBUG [php] Warning: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)
14:01:11 ERROR [app] Exception occurred while flushing email queue: Connection could not be established with host smtp.gmail.com [ #0]
作品:
配置/包/swiftmailer.yaml
swiftmailer:
transport: smtp
username: myemail@gmail.com
password: mypassword
host: smtp.gmail.com
port: 465
encryption: ssl
auth-mode: login
spool: { type: 'memory' }
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
verify_peer_name: false
不起作用:
.env
MAILER_TRANSPORT=smtp
MAILER_HOST=smtp.gmail.com
MAILER_USERNAME=myemail@gmail.com
MAILER_PASSWORD=mypassword
MAILER_PORT=465
MAILER_ENCRYPTION=ssl
配置/包/swiftmailer.yaml
swiftmailer:
transport: '%env(MAILER_TRANSPORT)%'
username: '%env(MAILER_USERNAME)%'
password: '%env(MAILER_PASSWORD)%'
host: '%env(MAILER_HOST)%'
port: '%env(MAILER_PORT)%'
encryption: '%env(MAILER_ENCRYPTION)%'
auth-mode: login
spool: { type: 'memory' }
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
verify_peer_name: false
当我这样做时,变量会出现并且设置得很好:
php bin/console about
bin/console debug:config swiftmailer
给我这个:
Current configuration for extension with alias "swiftmailer"
============================================================
swiftmailer:
default_mailer: default
mailers:
default:
transport: '%env(MAILER_TRANSPORT)%'
username: '%env(MAILER_USERNAME)%'
password: '%env(MAILER_PASSWORD)%'
host: '%env(MAILER_HOST)%'
port: '%env(MAILER_PORT)%'
encryption: '%env(MAILER_ENCRYPTION)%'
auth_mode: login
spool:
type: memory
path: 'C:\wamp\www\my-project\var\cache\dev/swiftmailer/spool'
id: null
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
verify_peer_name: false
delivery_addresses:
- myemail@gmail.com
url: null
command: '/usr/sbin/sendmail -bs'
timeout: 30
source_ip: null
local_domain: null
logging: true
delivery_whitelist: { }
我究竟做错了什么 ?