简体   繁体   English

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

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

This may not be a problem with MailGun as I was unable to send via Gmail aswell. 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 Guzzle installed, I have restated the web server and i know my details are correct. 我知道我已经安装了Guzzle ,我已经重新声明了Web服务器,并且我知道我的详细信息是正确的。 I'v created a test project to do only mail aswell to no avail. 我创建了一个测试项目,只做邮件也无济于事。

Could it be something todo with my host computer (macbook air) or that fact i'm using the development web server 这可能与我的主机(macbook air)有关,还是我正在使用开发Web服务器

 php artisan serve

I'm new to Laravel so i'm unsure of anything else I can do. 我是Laravel的新手,所以我不确定我还能做什么。

services.php services.php

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

mail.php mail.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. A已经停止使用env文件,因此它默认为mail.php,但是当属性的详细信息相同时,结果也相同。 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 是的,只是以防万一它询问我知道您已经更改了.env后需要重新启动服务器,并且为了安全起见,我在更改mail.php或services.php时一直在这样做

TestController.php TestController.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('us@example.com', 'Laravel');

            $message->to('dksnowdon@gmail.com');
        });

        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' => 'dksnowdon@gmail.com'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <us@example.com> To: dksnowdon@gmail.com 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' => 'dksnowdon@gmail.com'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <us@example.com> To: dksnowdon@gmail.com 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' => 'dksnowdon@gmail.com'), array('name' => 'message', 'contents' => 'Message-ID: <9975c6b7d34f1fc93864bf7ff15f702a@localhost> Date: Wed, 09 Dec 2015 03:08:38 +0000 From: Laravel <us@example.com> To: dksnowdon@gmail.com 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()

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

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-****',
    ],

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. 可能值得检查一下,是否像我一样真的将头撞在墙上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM