[英]Laravel 5.5 does not send e-mails
Hello I try send email from my registration script to user ( link ). 您好,我尝试将注册脚本中的电子邮件发送给用户( link )。 I have config file:
我有配置文件:
config/mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 's44.linuxpl.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'verify@coins.webmg.pl'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('verify@coins.webmg.pl'),
'password' => env('MySecretPassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'stream' => [
'tls' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
]
];
And file .env
: 和文件
.env
:
MAIL_DRIVER=smtp
MAIL_HOST=s44.linuxpl.com
MAIL_PORT=587
MAIL_USERNAME=verify@coins.webmg.pl
MAIL_PASSWORD=MySecretPassword
MAIL_ENCRYPTION=tls
Script to send mail from RegisterController.php
从
RegisterController.php
发送邮件的脚本
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
$verifyUser = VerifyUser::create([
'user_id' => $user->id,
'token' => str_random(40)
]);
$sendMail = Mail::to($user->email)->send(new VerifyMail($user));
return $user;
}
Class VerifyMail
类
VerifyMail
class VerifyMail extends Mailable
{
use Queueable, SerializesModels;
public $user;
public function __construct($user)
{
$this->user = $user;
}
public function build()
{
return $this->view('emails.verifyUser');
}
}
And file to send verifyUser.blade.php
并发送文件
verifyUser.blade.php
<h2>Welcome to the site {{$user['name']}}</h2>
I don't know what is wrong in this configuration, because I can log in correctly to the mailbox, so the email address and password are correct. 我不知道此配置有什么问题,因为我可以正确登录到邮箱,因此电子邮件地址和密码正确。 Additionally, laravel does not return any errors, the script itself is executed correctly.
此外,laravel不返回任何错误,脚本本身已正确执行。
Restore your mail.php
file to its defaults: 将您的
mail.php
文件恢复为其默认值:
Replace: 更换:
'username' => env('verify@coins.webmg.pl'),
'password' => env('MySecretPassword'),
with 同
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
You misunderstood how the env($key, $default = null)
method works. 您误解了
env($key, $default = null)
方法的工作方式。 The first argument it takes is the key of the environment variable (eg. 'MAIL_USERNAME'), and the second argument is the default value (which can be optional). 它采用的第一个参数是环境变量的键 (例如“ MAIL_USERNAME”),第二个参数是默认值(可以是可选的)。
Store your mail credentials in the .env
file only , and never within your config files' env()
calls. 仅将您的邮件凭据存储在
.env
文件中 ,而绝不将其存储在配置文件的env()
调用中。
I found solution. 我找到了解决方案。 The problem is with file
.env
. 问题在于文件
.env
。 The file was loaded with previous settings. 该文件已使用先前的设置加载。 It was enough to clean the cache files.
清理缓存文件就足够了。
php artisan config:cache
php artisan config:clear
php artisan cache:clear
Here it is well described Trying to get Laravel 5 email to work 在这里已经很好地描述了如何使Laravel 5电子邮件正常工作
just restore your config/mail.php to default one and try to set the below values in your laravel .env file directly 只需将config / mail.php恢复为默认值,然后尝试直接在laravel .env文件中设置以下值
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=abc@gmail.com
MAIL_PASSWORD=abc@123
May wish this will help you Thanks 希望这对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.