【问题标题】:Laravel with Mailgun setup带有 Mailgun 设置的 Laravel
【发布时间】:2016-11-10 18:35:57
【问题描述】:

我在使用 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');
}

我希望我只是看了一些简单的东西,这有时是最难解决的问题,但任何帮助都会有所帮助。谢谢。

【问题讨论】:

    标签: laravel mailgun laravel-mail


    【解决方案1】:

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

    '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
    

    希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-19
      • 2017-05-31
      • 2019-06-14
      • 1970-01-01
      • 1970-01-01
      • 2018-04-03
      • 2018-06-17
      • 1970-01-01
      相关资源
      最近更新 更多