下載 Amazon AWS SDK

  • 設定 composer.json
"require": {
    // ...

    "aws/aws-sdk-php": "~3.0"
},
  • 安裝
# 移至 laravel 資料夾內
$ composer update

SES config

.env

MAIL_DRIVER=ses
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=

SES_KEY=
SES_SECRET=
SES_REGION=

config\services.php

'ses' => [
    'key' => env('SES_KEY'),
    'secret' => env('SES_SECRET'),
    'region' => env('SES_REGION'),
],

Code

  • build mailable
$ php artisan make:mail TestMail

app\Mail\TestMail.php

public function build()
{
    return $this->view('emails.test');
}
  • view

resources\views\emails\test.blade.php

<h1>Hello</h1>
<h2>world</h2>
<p>!</p>
  • build controller
php artisan make:controller SendTestMail
  • routing

routes\web.php

Route::get('mail', 'SendTestMail@send');
  • controller

app\Http\Controllers\SendTestMail.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Mail\TestMail;
use Illuminate\Support\Facades\Mail;

class SendTestMail extends Controller
{
    public function send()
    {
        $email = '[email protected]';
        Mail::to($email)->send(new TestMail);
    }
}

Docs

Laravel

AWS

參考資料


錯誤處理

SesException

MessageRejected (client): Email address is not verified. The following identities failed the check in region

MAIL_FROM_ADDRESS 需對映 Email Address Identities

results matching ""

    No results matching ""