Laravel 5 이메일을 사용하려고합니다
URL을 입력하여 지정된 사용자에게 이메일을 보내려고하는데 다음 오류가 발생합니다.
AbstractSmtpTransport.php 383 줄의 Swift_TransportException : 응답 코드 250이 예상되었지만 메시지 "530"과 함께 코드 "530"이 표시됨 5.7.1 인증 필요
지금까지는 Gmail에서 작동하도록 노력하고 있습니다. 이 기능을 작동 시키려면 어떻게해야합니까?
이것은 내가 지금까지 가지고있는 것입니다 : mail.php
<?php
return [
'driver' => env('MAIL_DRIVER',' smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' =>"MyUsername@gmail.com" , 'name' => "example"],
'encryption' => 'tls',
'username' => env('MyUsername@gmail.com'),
'password' => env('MyPassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
이것이 내가 경로에 가지고있는 것입니다 :
Route::get('test', function() {
Mail::send('Email.test', [], function ($message) {
$message->to('example@gmail.com', 'HisName')->subject('Welcome!');
});
});
이것이 내 컨트롤러에있는 것입니다.
class MailController extends Controller
{
public function Sending_Email()
{
$this->call('GET','Email.test');
return View('Email.test');
}
}
그리고 이것은 내 .env 파일에 있습니다.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=MyUsername@gmail.com
MAIL_PASSWORD=MyPassword
나는 그것이 당신을 위해 지금 @ Vantheman6 작동한다는 것을 알고 있지만 이것이 다른 누군가와 같은 경우 나를 위해 일한 것입니다.
사용중인 메일 서비스의 세부 정보를 내 .env 파일에 추가했습니다. 다음 세부 사항을 확인하십시오
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=MyUsername@gmail.com
MAIL_PASSWORD=MyPassword
.env 파일의 내용이 정확합니다.
참고 : .env 파일을 편집 한 후 서버를 다시 시작해야 새 데이터가 저장됩니다.
서버를 다시 시작하지 않으면 .env 파일은이 오류의 원인이 될 수있는 변경 사항을 적용하더라도 이전 메일 데이터를 앱에 계속 제공합니다.
내 .env 파일 구성은 laravel 5.1의 경우와 같습니다
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=example@gmail.com
MAIL_PASSWORD=****************
MAIL_ENCRYPTION=tls
여기서 가장 중요한 것은 Gmail 응용 프로그램 특정 비밀번호 (16 자리)를 생성했다는 것입니다.
구성에 대한 운이 없기 때문에 한 가지 더 밝힐 필요가 있습니다. 즉, .env 파일을 변경할 때마다이 명령을 실행해야합니다.
php artisan config:cache
이 명령이 없으면 laravel이 캐시에서 이전 설정을 실행하기 때문에 가장 중요합니다. 알아내는 데 10 시간 이상이 걸렸습니다.
You are getting an authentication error because the username and password in your config file is setup wrong.
Change this:
'username' => env('MyUsername@gmail.com'),
'password' => env('MyPassword'),
To this:
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
The env
method checks your .env file. In your .env file you call these MAIL_USERNAME
, so that's what you need to pass to the env
method.
One troubleshooting tip: add dd(Config::get('mail'));
so that you can see the actual generated config. This will help you spot issues like this, and know exactly what information Laravel is going to try and use. So you may want to stop that in your test route temporarily to examine what you have:
Route::get('test', function()
{
dd(Config::get('mail'));
});
the problem will be solved by clearing cache
php artisan config:cache
Finally I got! Just to share, there are more config than just .env
This is .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=UserName@gmail.com
MAIL_PASSWORD=********
MAIL_ENCRYPTION=tls
config/mail.php also need to input address & name for it to work.
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'Username@gmail.com' , 'name' => 'YourName' ],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
For development purpose https://mailtrap.io/ provides you with all the settings that needs to be added in .env file. Eg:
Host: mailtrap.io
Port: 25 or 465 or 2525
Username: cb1d1475bc6cce
Password: 7a330479c15f99
Auth: PLAIN, LOGIN and CRAM-MD5
TLS: Optional
Otherwise for implementation purpose you can get the smtp credentials to be added in .env file from the mail (like gmail n all)
After addition make sure to restart the server
If you ever have the same trouble and try everything online and it doesn't work, it is probably the config cache file that is sending the wrong information. You can find it in bootstrap/cache/config.php. Make sure the credentials are right in there. It took me a week to figure that out. I hope this will help someone someday.
It happens to me also.
It is because when we edit the
.env
file we need to restart the server. Just stop the currentphp artisan serve
and start it once again. This will work for sure.
If still not worked try doing php artisan config:cache
For future reference to people who come here. after you run the command that was given in the third answer here(I am using now Laravel 5.3).
php artisan config:cache
You may encounter this problem:
[ReflectionException]
Class view does not exist
In that case, you need to add it back manually to your provider list under the app.php file. GO-TO: app->config->app.php->'providers[]'
and add it, like so:
Illuminate\View\ViewServiceProvider::class,
Hope That helps someone.
I've had the same problem; my MAIL_ENCRYPTION
was tls
on mail.php
but it was null
on .env
file.
So I changed null
to tls
and it worked!
None of the above solutions worked for me on localhost. I even allowed access from less secure apps, allowed access through display unlock captcha and set the verify peer and verify peer name to false for SSL.
Eventually, I used the open source SMTP testing solution of MailHog. The steps are as follows:
- Download the latest version of MailHog for your OS
- Specify the following settings in your .env file
MAIL_DRIVER=smtp
MAIL_HOST=127.0.0.1
MAIL_PORT=1025
MAIL_USERNAME=testuser
MAIL_PASSWORD=testpwd
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=theaddress@youwant.com
- Run the downloaded file of MailHog
- Send Email
- Check sent email by going to localhost:8025
That simply means that your server does not have access to the SMTP Server.
You can test this by doing:
telnet <smtpServer> <smtpPort>
You should get the Access denied error.
The solution is to just use another SMTP server that can be accessed by your server.
You should restart the server and run this commands:
php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan config:clear
php artisan config:cache
That should work.
If your results from dd(Config::get('mail'));
are null simply use the command
php artisan config:clear
I had the same problem as you, I just got it to work.
Firstly, you need to double check that the .env settings are set up correctly. Here are my settings:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=yourusername
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls
Please make sure that your password is not between quotes :).
And in config/mail.php it has the following, without the comments.
<?php
return [
'driver' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', '587'),
'from' => ['address' => 'yourusername', 'name' => 'yourname'],
'encryption' => env('MAIL_ENCRYPTION','tls'),
'username' => env('MAIL_USERNAME', 'username@gmail.com'),
'password' => env('MAIL_PASSWORD', 'password'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
Hope it works for you :)
In my case: Restart the server and run php artisan config:clear
command.
- You go to the Mailgun
- Click Authorized Recipients
- Add the email address you wish send mail to.
- Verify the message sent to the mail.
- Bravo!...You're good to go.
참고URL : https://stackoverflow.com/questions/29100877/trying-to-get-laravel-5-email-to-work
'Programing' 카테고리의 다른 글
공분산과 역 분산의 차이 (0) | 2020.06.16 |
---|---|
Chrome 콘솔에서 전체 개체를 표시하는 방법은 무엇입니까? (0) | 2020.06.16 |
구성 파일에서 ng serve의 기본 호스트 및 포트 설정 (0) | 2020.06.15 |
OpenCV2.0 및 Python2.6으로 이미지 크기를 조정하는 방법 (0) | 2020.06.15 |
Atom에서 코드 블록 주석 처리 (0) | 2020.06.15 |