如何使用邮件枪在 Laravel 中更改邮件中的发件人地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45415002/
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 change the sender address in mail in laravel with mail gun
提问by 06011991
I am sending the email using below code
我正在使用以下代码发送电子邮件
Mail::send('emails.sample',[],function($message) use($attachment,$filename)
{
$message->subject('PDF is generated !');
$message->from('[email protected]', 'Example');
$message->to('[email protected]');
$message->attachData($attachment,$filename,array('mime'=>'application/pdf','Content-Disposition'=>'attachment'));
});
but after receiving the email, sender email address is coming like this
但是在收到电子邮件后,发件人的电子邮件地址是这样的
[email protected] on behalf of Example [email protected]
[email protected] 代表 Example [email protected]
but it should be like either email address
or name
但它应该像要么email address
或name
测试@example.com
How do I fix this? any suggestions, please!
我该如何解决?任何建议,请!
回答by Gary Green
For anyone still reading this - it's because you need to set the "sender" address. Gmail doesn't seem to care, but Outlook does.
对于仍在阅读本文的任何人 - 这是因为您需要设置“发件人”地址。Gmail 似乎并不关心,但 Outlook 关心。
$message->sender(config('mail.from.address'));
回答by Luca C.
you can add these in .env
:
您可以将这些添加到.env
:
[email protected]
MAIL_FROM_NAME=From Name Surname
in alternative, if you let it blank, you can still change them in config/mail.php
, here replace with yours:
或者,如果您将其留空,您仍然可以将它们更改为config/mail.php
,此处替换为您的:
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'IDesk'),
],
as you can see config/mail.php
at first try to read it from .env
sto .env
should be used
正如您config/mail.php
首先看到的那样,应该使用.env
sto尝试读取它.env
回答by Masud Miah
In config/mail.php
在 config/mail.php
set from property as:
从属性设置为:
'from' => ['address' => '[email protected]', 'name' => 'Anything you Want']
回答by Kevin Patel
Are you using sandbox? Because I am also using the mailgun with sandbox and I am not facing this issue
你在使用沙盒吗?因为我也在沙箱中使用 mailgun 而我没有遇到这个问题
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=postmaster@sandbox3940xxxxxxxxxxxxxxxxxx.mailgun.org
MAIL_PASSWORD=xxxxxxxxxxxxxxxxxxxxxx
MAIL_ENCRYPTION=tls
MAILGUN_DOMAIN=sandboxxxxxxxxxxxxxxxxxxxfaf6.mailgun.org
MAILGUN_SECRET=key-xxxxxxxxxxxxxxxxxxxxxxxxx
回答by Otto
You'll need to set up some DNS records, so your mail provider can verify that mailgun is allowed to send email on behalf of your domain.
您需要设置一些 DNS 记录,以便您的邮件提供商可以验证是否允许 mailgun 代表您的域发送电子邮件。