无法在服务器中的Laravel中发送电子邮件 [英] Unable to send email in laravel in server
问题描述
我正在环境文件中进行配置,
I've following configuration in environment file,
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD='mypassword'
MAIL_ENCRYPTION=ssl
我已经从RegistrationController
进行了用户注册,并发送电子邮件以验证该用户.它可以在具有ubantu的本地LAMP服务器中完美运行.但是,在C Panel中遇到以下错误.
I've made user registration from RegistrationController
and send email to verify that user. It works perfectly in the local LAMP server with ubantu. But, following error is encountered in C Panel.
Swift_TransportException无法使用以下方法建立连接 主机smtp.gmail.com [网络无法访问#101]
Swift_TransportException Connection could not be established with host smtp.gmail.com [Network is unreachable #101]
这是控制器中的寄存器功能,
Here is the register function in controller,
protected function register(Request $request)
{
/** @var User $user */
$validatedData = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
try {
$validatedData['password'] = bcrypt(array_get($validatedData, 'password'));
$validatedData['activate_code'] = str_random(30).time();
if($request->has('company') && $request->company=='on')
{
$validatedData['role_id'] = 4;
}
else
{
$validatedData['role_id'] = 5;
}
$user = app(User::class)->create($validatedData);
} catch (\Exception $exception) {
logger()->error($exception);
return redirect()->back()->with('alert-danger', 'Unable to create new user.');
}
$user->notify(new UserRegisteredSuccessfully($user));
return redirect()->back()->with('alert-success', 'Successfully created a new account. Please check your email and activate your account.');
}
我已经看到过这样的问题,并且有很多疑问,但是对于我而言,没有任何效果.任何帮助都将受到赞赏.
I've already seen such issues and many question but none works in my case. Any kind of help is appreciated.
推荐答案
首先,一旦您创建了用于从您的网站发送邮件的gmail帐户,则必须授予您的gmail帐户用于从其他应用程序发送邮件的权限. 为此...
firstable, once you have created gmail account for mailing from your website, You must give a permission your gmail account for mailing from other app. to do this...
1)转到您的Gmail帐户,然后单击"settings -> FORWARDING and POP/IMAP
"链接.并按照下图所示的说明进行操作...
1) go to your gmail account and click on "settings -> FORWARDING and POP/IMAP
" link. And follow these instructions like below picture...
2)转到此链接https://myaccount.google.com/lesssecureapps?utm_source=google-account&utm_medium=web
并启用如下图所示的内容...
2) go to this link https://myaccount.google.com/lesssecureapps?utm_source=google-account&utm_medium=web
and enable this like below picture...
3)确保如果您的Web应用程序正在使用http协议,请使用MAIL_ENCRYPTION=tls
和MAIL_PORT=587
,否则使用MAIL_ENCRYPTION=ssl
和MAIL_PORT=465
3) make sure thst if your web app is working on http protocol use MAIL_ENCRYPTION=tls
and MAIL_PORT=587
otherwise MAIL_ENCRYPTION=ssl
and MAIL_PORT=465
这篇关于无法在服务器中的Laravel中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!