我最近接手了一个Laravel项目,我正在设置开发环境,其中包括配置项目使用MySQL数据库。我已经成功地配置了大部分的环境设置;然而,我遇到了一个问题与电子邮件确认功能.尽管对.env文件进行了更改以指向正确的邮件服务器,但应用程序似乎仍在尝试使用上一个项目中的邮件服务器设置。这将导致以下错误消息:
Connection could not be established with host previous.group.mailserver.com :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: The specified host is unknown.
我还更改了Mail:send的所有用途,以使用我的开发电子邮件:
Mail::send($view, $mail_data, function ($message) use ($mail_data) {
$message->to($mail_data['receiver_mail'], $mail_data['receiver_name'] . " " . $mail_data['receiver_surname'])->bcc('X', 'X')->subject('Confirmation Mail');
});
mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => '[email protected]',
'name' => 'development email',
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
];
.env
APP_NAME=X
APP_ENV=local
APP_KEY=X
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http:http://localhost
UNIQUE_SERVER_URL=X/
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=X
MAIL_PASSWORD=X
MAIL_ENCRYPTION=ssl
DATABASE=X
DATABASE_USERNAME=X
DATABASE_PASSWORD=X
composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"barryvdh/laravel-cors": "^0.11.2",
"fideloper/proxy": "~3.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0"
},
"require-dev": {
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"ThekRe\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true,
"allow-plugins": {
"kylekatarnls/update-helper": true
}
}
}
我也按照类似问题的指示做了,但没有成功:
Connection could not be established with host mailtrap.io [php_network_getaddresses: getaddrinfo failed: No such host is known. #0]
1条答案
按热度按时间pieyvz9o1#
您正在使用Gmail有使用它之前的规则:
https://support.google.com/accounts/answer/185833?hl=en
登录到您的Gmail帐户,并在我的帐户>登录和安全>登录到谷歌,启用两步验证,然后您可以生成应用程序密码,您可以使用该应用程序密码在**.env**文件。
我建议使用mailtrap,它易于使用,适合本地测试