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

时间:2015-12-09 01:07:29

标签: php email laravel mailgun

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

我看到的错误如下所示,你可以看到域名应该通过的地方但是没有。

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

域名应为

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

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

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

 php artisan serve

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

services.php

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

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),

已停止使用env文件,因此它默认为mail.php,但当属性相同时,结果相同。是的,只是因为它的问题,我知道你需要重新启动服务器,当你改变.env并且只是在安全的网站上我一直在改变mail.php或services.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');
    }
}

确切的错误

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()

3 个答案:

答案 0 :(得分:29)

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

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

然后在.env中你需要把:

MAILGUN_DOMAIN=yourdomain
MAILGUN_SECRET=yoursecret

答案 1 :(得分:2)

除了kEpEx的答案,您可以从services.php config中删除env()部分

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

答案 2 :(得分:2)

如果有人在努力解决这个问题,我会在一段时间后发现我的主机阻止了所有外部邮件服务器。

他们只允许我使用他们自己的邮件服务器。如果你真的像我一样猛烈地撞击墙壁,可能值得一试。