使用带有 laravel 的 mailcatcher 时遇到错误(“laravel/framework”:“^8.54”,)
"message": "Connection could not be established with host localhost :stream_socket_client(): unable to connect to localhost:8003 (Cannot assign requested address)",
"exception": "Swift_TransportException",
"file": "/var/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php",
"line": 261,
所以,我像往常一样发送电子邮件,我检查了使用的默认邮件smpt
配置/邮件.php
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
在代码中
use Illuminate\Support\Facades\Mail;
//
Mail::send((new ContactUsEmail($contactUs)));
我的 .env
MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=8003
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=from_admin@admin.com
MAIL_TO_ADDRESS=to_admin@admin.com
MAIL_FROM_NAME="${APP_NAME}"
MAIL_TO_NAME=admin
当我在 \Swift_Transport_StreamBuffer 中调试它时
params = {array} [8]
protocol = ""
host = "localhost"
port = {int} 8003
timeout = {int} 30
blocking = {int} 1
tls = false
type = {int} 1
stream_context_options = {array} [0]
看起来端口正确
当我打开 mailcatcher 时可用http://localhost:8100/
码头工人撰写 yml:
php-larabostad:
build:
context: .
dockerfile: ./php/Dockerfile
restart: on-failure
volumes:
- "../:/var/www"
- "./php/php.ini:/usr/local/etc/php/conf.d/custom.ini"
- "./data/php:/var/larabostad:z"
networks:
- php-larabostad-networks
- mysql-larabostad-networks
- mailcatcher-larabostad-networks
mailcatcher:
image: schickling/mailcatcher:latest
container_name: myapp-mailcatcher
ports:
- "8003:1025"
- "8100:1080"
networks:
- mailcatcher-larabostad-networks
码头工人撰写ps
docker_nginx-larabostad_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:443->443/tcp,:::443->443/tcp,
0.0.0.0:80->80/tcp,:::80->80/tcp
docker_php-larabostad_1 bash /usr/local/bin/docker ... Up 9000/tcp
myapp-mailcatcher mailcatcher --no-quit --fo ... Up 0.0.0.0:8003->1025/tcp,:::8003->1025/tcp,
0.0.0.0:8100->1080/tcp,:::8100->1080/tcp
mysql8 docker-entrypoint.sh mysql ... Up 0.0.0.0:3306->3306/tcp,:::3306->3306/tcp, 33060/tcp
我做错了什么?
更新
从 php 容器执行 ping
/var/www# ping mailcatcher
PING mailcatcher (172.23.0.2) 56(84) bytes of data.
64 bytes from myapp-mailcatcher.docker_mailcatcher-larabostad-networks (172.23.0.2): icmp_seq=1 ttl=64 time=0.237 ms
64 bytes from myapp-mailcatcher.docker_mailcatcher-larabostad-networks (172.23.0.2): icmp_seq=2 ttl=64 time=0.138 ms
新错误
"message": "Connection could not be established with host mailcatcher :stream_socket_client(): unable to connect to mailcatcher:8003 (Connection refused)",
"exception": "Swift_TransportException",
"file": "/var/www/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php",
"line": 261,