使用Mailgun设置的Laravel

时间:2016-11-10 18:35:57

标签: laravel mailgun laravel-mail

我在使用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 Class包含以下内容:

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');
}

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

1 个答案:

答案 0 :(得分:0)

如果您想使用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

希望这有帮助!