Laravel 如何配置发件人姓名而不是电子邮件地址

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

Laravel how to configure sender name instead of email address

phplaravelemail

提问by Muhammad Kazim

How do I configure the sender name in the .envor mail.phpfiles in Laravel? I set the email configuration in both of these files as below.

如何在Laravel 的 .envmail.php文件中配置发件人名称?我在这两个文件中设置了电子邮件配置,如下所示。

.env:

.env:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=jayabahadurgmail.com
MAIL_PASSWORD=9491A$$R
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS = [email protected]
MAIL_FROM_NAME = NO-REPLY

config/mail.phpfile:

配置/mail.php文件:

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

The issue is that when I receive an email, it shows my email address like "jayabahadurgmail.com", but I want to show "NO-REPLY" instead of my email.

问题是当我收到一封电子邮件时,它显示我的电子邮件地址,如“jayabahadurgmail.com”,但我想显示“NO-REPLY”而不是我的电子邮件。

回答by Cy Rossignol

Gmail automatically rewrites the "from" header of any messages sent through its SMTP server to the default "Send mail as" email address assigned in the Gmail or Google Apps account used to authenticate (in this case, your personal account).

Gmail 会自动将通过其 SMTP 服务器发送的任何邮件的“发件人”标头重写为用于进行身份验证的 Gmail 或 Google Apps 帐户(在本例中为您的个人帐户)中分配的默认“发送邮件为”电子邮件地址。

This SMTP service is intended for personal use only, so its not very flexible. We can change this address by modifying the default account in the Gmail settings, but this still won't enable us to configure the "from" address through the application.

此 SMTP 服务仅供个人使用,因此不是很灵活。我们可以通过修改 Gmail 设置中的默认帐户来更改此地址,但这仍然无法让我们通过应用程序配置“发件人”地址。

In development, this behavior may not matter, but for production environments, we'd need to use a mail provider that respects the headers sent from the application. Gmail also limits the rate of emails sent through its SMTP server in this way, which prevents us from using the service for most applications in production that send any significant amount of email.

在开发中,这种行为可能无关紧要,但对于生产环境,我们需要使用尊重从应用程序发送的标头的邮件提供程序。Gmail 还以这种方式限制了通过其 SMTP 服务器发送电子邮件的速率,这使我们无法将该服务用于生产中发送大量电子邮件的大多数应用程序。

回答by ZeroOne

just go to mail.php and edit

只需转到mail.php并编辑

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
    'name' => env('MAIL_FROM_NAME', 'BePunct'),
],

save. That's all. Make sure you config:clearto load the .env

节省。就这样。确保你config:clear加载了 .env

Tested with Mailgun and Mailtrap.. Gmail i think it is not supported yet..

用 Mailgun 和 Mailtrap 测试过.. Gmail 我认为它还不支持..

If you are using queue.. restart the queue.. and try it again

如果您正在使用队列.. 重新启动队列.. 然后再试一次