Markdown Mail
Laravel Mail: Markdown Mail
Configuration
config/mail.php
composer require symfony/mailgun-mailer symfony/http-client
Plan | Pricing | Description |
---|---|---|
Trial | $0/month | 5,000 emails/month included |
Foundation | $35/month | 50,000 emails/month included |
Growth | $80/month | 100,000 emails/month included |
Scale | $90/month | 100,000 emails/month included |
.env
& config/mail.php
// config/mail.php
return [
'default' => env('MAIL_MAILER', 'smtp'),
];
# .env
MAIL_MAILER=mailgun
.env
& config/services.php
// config/services.php
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
# .env
MAILGUN_DOMAIN=
MAILGUN_SECRET=
If you are not using the United States Mailgun region
, you may define your region’s endpoint in the services configuration file:
// config/services.php
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.eu.mailgun.net'),
],
# .env
MAILGUN_DOMAIN=
MAILGUN_SECRET=
MAILGUN_ENDPOINT=
composer require aws/aws-sdk-php
Service type | Volume per month | Price | Additional charges |
---|---|---|---|
Outbound email from EC2 | 0-62,000 emails | $0 | $0.12 for each GB of attachments you send |
Outbound email from EC2 | >62,000 emails | $0.10/1000 emails | $0.12 for each GB of attachments you send |
Outbound email from non-EC2 | Flat | $0.10/1000 emails | $0.12 for each GB of attachments you send |
Inbound email | 0-1,000 emails | $0 | $0.09 for every 1,000 incoming email chunks |
Inbound email | >1,000 emails | $0.10/1000 emails | $0.09 for every 1,000 incoming email chunks |
.env
& config/mail.php
// config/mail.php
return [
'default' => env('MAIL_MAILER', 'smtp'),
];
MAIL_MAILER=ses
.env
& config/services.php
// config/services.php
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
# .env
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
To utilize AWS temporary credentials via a session token, you may add a token key
to your application’s SES configuration:
// config/services.php
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'token' => env('AWS_SESSION_TOKEN'),
],
# .env
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
AWS_SESSION_TOKEN=
If you would like to define additional options that Laravel should pass to the AWS SDK’s SendEmail
method when sending an email, you may define an options
array within your ses configuration
:
// config/services.php
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'options' => [
'ConfigurationSetName' => 'MyConfigurationSet',
'EmailTags' => [
['Name' => 'foo', 'Value' => 'bar'],
],
],
],
return new Envelope(
from: new Address('jeffrey@example.com', 'Jeffrey Way'),
replyTo: [
new Address('taylor@example.com', 'Taylor Otwell'),
],
subject: 'Order Shipped',
);
// config/mail.php
'from' => [
'address' => 'example@example.com',
'name' => 'App Name'
],
// config/mail.php
'reply_to' => [
'address' => 'example@example.com',
'name' => 'App Name'
],
use Illuminate\Support\Facades\Mail;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
if ($this->app->environment('local')) {
Mail::alwaysTo('taylor@example.com');
}
}
backup mail delivery configurations
// config/mail.php
'mailers' => [
'failover' => [
'transport' => 'failover',
'mailers' => [
'postmark',
'mailgun',
'sendmail',
],
],
],
use Illuminate\Support\Facades\Mail;
Mail::to($request->user())->send(new OrderShipped($order));
Mail::to($request->user())
->cc($moreUsers)
->bcc($evenMoreUsers)
->send(new OrderShipped($order));
Mail::mailer('ses')
->to($request->user())
->send(new OrderShipped($order));
Mail::to($request->user())
->cc($moreUsers)
->bcc($evenMoreUsers)
->queue(new OrderShipped($order));
Mail::to($request->user())
->cc($moreUsers)
->bcc($evenMoreUsers)
->later(now()->addMinutes(10), new OrderShipped($order));
$OrderShippedMailable = (new OrderShipped($order))
->onConnection('sqs')
->onQueue('emails');
Mail::to($request->user())
->cc($moreUsers)
->bcc($evenMoreUsers)
->queue($OrderShippedMailable);
class OrderShipped extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
public function __construct()
{
// The name of the connection the job should be sent to.
$this->onConnection('redis')
// The name of the queue the job should be sent to.
->onQueue('email');
}
}
Mail::to($request->user())->locale('zh_TW')->send(
new OrderShipped($order)
);
use Illuminate\Contracts\Translation\HasLocalePreference;
class User extends Model implements HasLocalePreference
{
/**
* Get the user's preferred locale.
*
* @return string
*/
public function preferredLocale()
{
return $this->locale;
}
}
Mail::to($request->user())->send(new OrderShipped($order));