如何配置 Laravel mail.php 使用内置邮件功能?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43525560/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:51:24  来源:igfitidea点击:

How to configure Laravel mail.php to use built-in mail function?

phplaravelemail

提问by Oleg

I need to send an email via the mail()PHP function. I've read somewhere that I have to change driverparameter in config/mail.phpto sendmail.

我需要通过mail()PHP 函数发送电子邮件。我在某处读到我必须将driver参数更改config/mail.phpsendmail.

By default, it looks like this:

默认情况下,它看起来像这样:

'driver' => env('MAIL_DRIVER', 'smtp'),

Now, it looks like this:

现在,它看起来像这样:

'driver' => 'sendmail',

Also tried this:

也试过这个:

'driver' => 'mail',

But still, the mail()function doesn't work. What do I need to change?

但是,该mail()功能仍然不起作用。我需要改变什么?

采纳答案by AddWeb Solution Pvt Ltd

You can set your mail configuration .envfile like

您可以将邮件配置.env文件设置为

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD="password"
MAIL_ENCRYPTION=tls

also set configuration in config/mail.php like:

还可以在 config/mail.php 中设置配置,例如:

'from' => ['address' => '[email protected]', 'name' => 'Test'],

'from' => ['address' => '[email protected]', 'name' => 'Test'],

then you can clear the cache:

然后你可以清除缓存:

php artisan cache:clear
php artisan config:cache
php artisan cache:clear

回答by Max Oriola

To do the same as mail() PHP function does, in most cases you should configure Laravel in the following way:

要执行与 mail() PHP 函数相同的操作,在大多数情况下,您应该按以下方式配置 Laravel:

Use sendmail, at .env:

在 .env 中使用 sendmail:

MAIL_DRIVER=sendmail

Host, user, password, port and encryption are not needed.

不需要主机、用户、密码、端口和加密。

At this point, you may check if it already works, but sometimes the next step is also needed.

此时,您可以检查它是否已经工作,但有时还需要下一步。

Set a new .env option in config/mail.php:

在 config/mail.php 中设置一个新的 .env 选项:

'sendmail' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail -bs')

Set the sendmail path in .env. You can check sendmail_pathat phpinfo(), but it's usually this one:

在 .env 中设置 sendmail 路径。您可以查看sendmail_pathphpinfo(),但通常是这样的:

MAIL_SENDMAIL='/usr/sbin/sendmail -t -i'

回答by Ikbel

To use the email server running on localhost, your .envfile should look like this (The PHP mailfunction doesn't need a username or a password)

要使用运行在 上的电子邮件服务器localhost,您的.env文件应如下所示(PHPmail函数不需要用户名或密码)

MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null

Then, update the configuration cache:

然后,更新配置缓存:

php artisan config:cache

回答by Jagdish Chaudhary

You have to set your mail Configuration in .env file. Here you have to set all your mail driver and all details. Plase see this documentation https://laravel.com/docs/5.0/mail

您必须在 .env 文件中设置邮件配置。在这里,您必须设置所有邮件驱动程序和所有详细信息。请参阅此文档https://laravel.com/docs/5.0/mail