Laravel 不会将我的域传递给 MailGun 驱动程序,因此我无法发送邮件

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

Laravel won't pass my domain to the MailGun driver so I can't send mail

phpemaillaravelmailgun

提问by kEpEx

This may not be a problem with MailGunas I was unable to send via Gmailaswell.

这可能不是MailGun的问题,因为我也无法通过Gmail发送。

The error i'm getting as seen below you can see where the domain should be passed but hasn't.

我得到的错误如下所示,您可以看到应该传递域但没有传递的位置。

POST https://api.mailgun.net/v3//messages.mime

the domain should be

域应该是

POST https://api.mailgun.net/v3/domin/messages.mime

I know I have Guzzleinstalled, I have restated the web server and i know my details are correct. I'v created a test project to do only mail aswell to no avail.

我知道我已经安装了Guzzle,我已经重新启动了 Web 服务器并且我知道我的详细信息是正确的。我创建了一个测试项目,只做邮件也无济于事。

Could it be something todo with my host computer (macbook air) or that fact i'm using the development web server

这可能是我的主机(macbook air)或我正在使用开发网络服务器的事实

 php artisan serve

I'm new to Laravelso i'm unsure of anything else I can do.

我是Laravel 的新手,所以我不确定我还能做什么。

services.php

服务.php

  'mailgun' => [
        'domain' => env('sandbox*****.mailgun.org'),
        'secret' => env('key-**************'),
    ],

mail.php

邮件.php

'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
 'port' => env('MAIL_PORT', 587),
'from' => ['address' => null, 'name' => null],
 'encryption' => env('MAIL_ENCRYPTION', 'tls'),
 'username' => env('postmaster@sandbox***********.mailgun.org'),
  'password' => env('sandboxpassword'),
 'sendmail' => '/usr/sbin/sendmail -bs',
 'pretend' => env('MAIL_PRETEND', false),

A've stopped using the env file so it defaults to the mail.php, but when the attributes are the same details it's the same outcome. And yeah just incase its asked i'm aware you need to restart the server when you've changed the .env and just to be on the safe site i've been doing it when changing the mail.php or services.php

A 已经停止使用 env 文件,所以它默认为 mail.php,但是当属性是相同的细节时,它的结果是相同的。是的,只是因为它询问我知道您需要在更改 .env 时重新启动服务器,并且只是为了在安全站点上我在更改 mail.php 或 services.php 时一直在这样做

TestController.php

测试控制器.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Mail;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class TestController extends Controller
{
    public function index() {
        Mail::raw('Text to e-mail', function ($message) {
            $message->from('[email protected]', 'Laravel');

            $message->to('[email protected]');
        });

        return view('welcome');
    }
}

the exact error

确切的错误

ClientException in RequestException.php line 107:
Client error: `POST https://api.mailgun.net/v3//messages.mime` resulted in a `404 NOT FOUND` response:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested (truncated...)
in RequestException.php line 107
at RequestException::create(object(Request), object(Response)) in Middleware.php line 65
at Middleware::GuzzleHttp\{closure}(object(Response)) in Promise.php line 199
at Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) in Promise.php line 152
at Promise::GuzzleHttp\Promise\{closure}() in TaskQueue.php line 60
at TaskQueue->run(true) in Promise.php line 240
at Promise->invokeWaitFn() in Promise.php line 217
at Promise->waitIfPending() in Promise.php line 261
at Promise->invokeWaitList() in Promise.php line 219
at Promise->waitIfPending() in Promise.php line 62
at Promise->wait() in Client.php line 129
at Client->request('post', 'https://api.mailgun.net/v3//messages.mime', array('auth' => array('api', null), 'multipart' => array(array('name' => 'to', 'contents' => '[email protected]'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <[email protected]> To: [email protected] MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Text to e-mail', 'filename' => 'message.mime')))) in Client.php line 87
at Client->__call('post', array('https://api.mailgun.net/v3//messages.mime', array('auth' => array('api', null), 'multipart' => array(array('name' => 'to', 'contents' => '[email protected]'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <[email protected]> To: [email protected] MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Text to e-mail', 'filename' => 'message.mime'))))) in MailgunTransport.php line 79
at Client->post('https://api.mailgun.net/v3//messages.mime', array('auth' => array('api', null), 'multipart' => array(array('name' => 'to', 'contents' => '[email protected]'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <[email protected]> To: [email protected] MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Text to e-mail', 'filename' => 'message.mime')))) in MailgunTransport.php line 79
at MailgunTransport->send(object(Swift_Message), array()) in Mailer.php line 85
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php line 395
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 181
at Mailer->send(array('raw' => 'Text to e-mail'), array(), object(Closure)) in Mailer.php line 133
at Mailer->raw('Text to e-mail', object(Closure)) in Facade.php line 219
at Facade::__callStatic('raw', array('Text to e-mail', object(Closure))) in TestController.php line 17
at Mail::raw('Text to e-mail', object(Closure)) in TestController.php line 17
at TestController->index()

回答by kEpEx

You need to leave the services.php config as default:

您需要将 services.php 配置保留为默认值:

'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
    ],

Then in the .env you need to put:

然后在 .env 中,您需要放置:

MAILGUN_DOMAIN=yourdomain
MAILGUN_SECRET=yoursecret

回答by CoredusK

Alternatively to kEpEx's answer, you can remove the env() part from services.php config

替代 kEpEx 的答案,您可以从 services.php 配置中删除 env() 部分

 'mailgun' => [
        'domain' => 'sandbox******.mailgun.org',
        'secret' => 'key-****',
    ],

回答by CoredusK

In case someone is struggling with this, I found out after a while that my host was blocking all external mail servers.

万一有人为此苦苦挣扎,我发现我的主机阻止了所有外部邮件服务器。

They only allowed me to use their own mail servers. Might be worth checking if you're really bashing your head against the wall like I did.

他们只允许我使用他们自己的邮件服务器。可能值得检查一下,您是否真的像我一样用头撞墙。