0

我在使用 Laravel 设置 Mailgun 时遇到问题。我不断收到以下消息:

ClientException in RequestException.php line 111:
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...)

不知道该怎么办。这是我遵循的基本设置:

.env 文件

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME='sandbox8e8c3965d4d14cac9d4f346c3d******'
MAIL_PASSWORD='e662ad1bbef5efd44cb96d32d6******'
MAIL_ENCRYPTION=tls

config/mail.php 文件

'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
    'address' => 'west**********@gmail.com',
    'name' => 'My Name is here',
],
 'encryption' => env('MAIL_ENCRYPTION', 'tls'),
 'username' => env('MAIL_USERNAME'),
 'password' => env('MAIL_PASSWORD'),
 'sendmail' => '/usr/sbin/sendmail -bs',

我的路线文件包含以下内容

Route::post('sendMail', function(\Illuminate\Mail\Mailer $mailer, \Illuminate\Http\Request $request) {

$title = $request->title;
$content = $request->content;

$mailer->to('westtexascentral@gmail.com')->send(new \App\Mail\MyMailer($title, $content));

return 'Mail sent.';
});

我的 Mailer 类包含以下内容:

public $title;
public $content;

/**
 * Create a new message instance.
 *
 * @return void
 */
public function __construct($title, $content)
{
    $this->title = $title;
    $this->content = $content;
}

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from('kaley36_aw@yahoo.com')->view('emails.mail');
}

我希望我只是看起来很简单,这有时是最难解决的问题,但任何帮助都会有所帮助。谢谢你。

4

1 回答 1

0

如果你想使用 Mailgun 驱动程序(通过他们的 API 使用 Mailgun),你必须设置你的 Mailgun 的秘密和域config/services.php

'mailgun' => [
    'domain' => 'your-mailgun-domain',
    'secret' => 'your-mailgun-key',
],

并且不要忘记安装所需的Guzzle软件包。打开终端并运行:

composer require guzzlehttp/guzzle

如果您通过 API 使用 Mailgun,只需确保在您的.env文件中设置了这一行:

MAIL_DRIVER=mailgun

实际上,您可以忽略.env文件中的以下指令。如果您使用的是 SMTP 协议,则使用它:

MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME='sandbox8e8c3965d4d14cac9d4f346c3d******'
MAIL_PASSWORD='e662ad1bbef5efd44cb96d32d6******'
MAIL_ENCRYPTION=tls

希望这有帮助!

于 2016-11-10T19:49:43.640 回答