Laravel版本-8
我想做什么
发送不带env变量的电子邮件。
错误详细信息
Connection could not be established with host mailhog :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: No such host is known.
我遗漏了什么吗?
代码
config('MAIL_DRIVER', 'smtp');
config('MAIL_USERNAME', "email username");
config('MAIL_HOST', "smtp.gmail.com");
config('MAIL_PASSWORD', "password");
config('MAIL_PORT', "port");
config('MAIL_ENCRYPTION', "tls");
$invitedUser = new Admin();
$invitedUser->email = "recipient email address";
$invitedUser->notify(new TestingNotification());
config(['mail.mailers.smtp.host' => "host"]);
config(['mail.mailers.smtp.encryption' => "tls"]);
config(['mail.mailers.smtp.username' => "username"]);
config(['mail.mailers.smtp.password' => "password"]);
config(['mail.mailers.smtp.port' => "port"]);
config(['mail.mailers.smtp.from' => "from"]);
$invitedUser = new Admin();
$invitedUser->email = "recipient";
$invitedUser->notify(new TestingNotification());
您的配置似乎有问题。该错误提到mailhog
是主机,但这可能不是您想要的。
也许你把config('MAIL_HOST', "smtp.gmail.com");
之类的东西写成了伪代码,但通常你会在mail.php
配置文件中设置它。例如:
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.gmail.com'),`.
...
]
]