Laravel version - 8
What Am I trying to do?
Sending email without env variable.
Error Details
Connection could not be established with host mailhog :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: No such host is known.
Am i missing anything?
Code
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());
CodePudding user response:
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());
CodePudding user response:
It seems like there's something wrong with your configuration. The error mentions mailhog
as a host, but that probably is not what you wanted.
Maybe you wrote things like config('MAIL_HOST', "smtp.gmail.com");
as pseudo code, but usually you'd set this up in your mail.php
config file. For example:
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.gmail.com'),`.
...
]
]