LoginSignup
2
3

More than 5 years have passed since last update.

cakephp3 で sendgrid 使おうぜ

Last updated at Posted at 2018-10-22

sendgrid って何よ?

使うと迷惑メールにならんのよ。

特徴は?

webapi 早い
smtp 遅い

設定

から申し込む。
1社につき、1アカウントしか使えんみたいんなので、注意。

設定

以下をクリックしてから

※画像が間違っている。MailSettingsの下の
Sender Authentication をクリックする

SendGrid.png

参考に設定(情報がちょい古い)
https://xn--hckj0bf8p.com/wordpress-mail-does-not-arrive-and-delayed-resolve-with-sendgrid/

まぁCNAMEをコピペしてくだけなんだけど。

APIキーを取得

SendGrid (1).png

一回しか表示できんので、
ちゃんとメモること。

CAKEPHP3で使おうぜ

composer でインストール


composer require iandenh/cakephp-sendgrid

app.php


    'EmailTransport' => [
        'SendgridEmail' => [
            'className' => 'SendgridEmail.Sendgrid',
            'api_key' => '[YOURKEY]'
        ]
    ],

    'Email' => [

        'Sendgrid' => [
            'transport' => 'SendgridEmail',
        ],
    ],


を設定。

いざ送信


        //    use Cake\Mailer\Email;


        //そのまま送る
        $email = new Email('Sendgrid');
        $email->from(['from@from.com' => 'ふろーむ'])
            ->transport('SendgridEmail')//config変更

            ->to('send@sendo.com')
        ->subject('こんにちわ。')
        ->send('
        はじめまして。
        https://yahoo.co.jp
        にご登録頂きありがとうございます。');




これで送信できます。

変なurl に飛ぶやん?

SMTPまたはWeb APIを利用している場合

Settings>Tracking>Click Tracking設定から無効化できます。くわしくはユーザマニュアルをご覧ください。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3