如何使用 cPanel 电子邮件帐户在 Laravel 中发送确认电子邮件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38601527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use cPanel email accounts to send confirmation emails in laravel?
提问by Paul Lucero
I have uploaded my laravel project onto the production server. Locally, I was using my personal gmail account to send confirmation emails to new users. Since I've uploaded it already, I created an email account in cpanel "[email protected]". How do I use this in my Laravel project?
我已将我的 Laravel 项目上传到生产服务器。在本地,我使用我的个人 gmail 帐户向新用户发送确认电子邮件。由于我已经上传了它,我在 cpanel“[email protected]”中创建了一个电子邮件帐户。我如何在我的 Laravel 项目中使用它?
- Can I use this to send email confirmations to new users? Or do I need to create another service provider like Mandrill or Mailchimp?
- If I can use this, what is the settings? Sorry I'm very new.
- 我可以使用它向新用户发送电子邮件确认吗?或者我是否需要创建另一个服务提供商,如 Mandrill 或 Mailchimp?
- 如果我可以使用这个,设置是什么?对不起,我很新。
回答by edCoder
In .env
file add following details
在.env
文件中添加以下详细信息
MAIL_DRIVER=smtp
MAIL_HOST=your_host
MAIL_PORT=your_port
MAIL_USERNAME=your_mail_username
MAIL_PASSWORD=your_mail_password
MAIL_ENCRYPTION=your_encryption
回答by Akram Wahid
open config/mail.php, .env files and set your email driver as mail as bellow,
打开 config/mail.php, .env 文件并将您的电子邮件驱动程序设置为邮件,如下所示,
'driver' => env('MAIL_DRIVER', 'mail'), //you must set it in env file too
then you can send emails like bellow, note that emails.admin.member, is the path to your email template, in the example code, laravel will look for a blade template in the path, resources\views\emails\admin\member.blade.php
然后你可以像下面这样发送电子邮件,注意emails.admin.member,是你的电子邮件模板的路径,在示例代码中,laravel会在路径中寻找刀片模板, resources\views\emails\admin\member.blade.php
Mail::queue('emails.admin.member', $data, function($message) {
$message->subject("A new Member has been Registered" );
$message->from('[email protected]', 'Your application title');
$message->to('[email protected]');
});
or use send function
或使用发送功能
Mail::send('emails.admin.member', $data, function($message) {
$message->subject("A new Member has been Registered" );
$message->from('[email protected]', 'Your application title');
$message->to('[email protected]');
});
the difference between them is, if you have a performance concern, go for queue method and it will send the emails in the background process without waiting to process the script, send function will wait until the emails be sent to continue the script..
它们之间的区别在于,如果您有性能问题,请使用 queue 方法,它将在后台进程中发送电子邮件而无需等待处理脚本,发送函数将等到发送电子邮件以继续脚本..