LoginSignup
1
3

More than 5 years have passed since last update.

CakePHP3でSendGridメールにヘッダーを追加する

Posted at

SendGridを使ってメールを送りたかった。
SendGridはメールにX-SMTPAPIヘッダーを加えて、値にcategoryを設定するとcategoryごとの数値が取得出来るため、CakePHP3でメールを送る際にヘッダーを追加する必要があった。

// SendGridでの効果測定用ヘッダー
$xSmtpHeader = ['X-SMTPAPI' => json_encode(['category' => 'remaind day'])];

$email = new Email("default");
$email->setTransport('SendGrid');
$email->setTemplate("template_name")
      ->setLayout("")
      ->setEmailFormat('html')
      ->setViewVars([
        'email' => $email,
        'name' => $name
    ])
    ->setTo($email)
    ->setSubject('タイトル')
    ->setFrom(Configure::read('email.support'))
    // SendGridでの効果測定用ヘッダー追加
    ->addHeaders($xSmtpHeader)
    ->send();
1
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
1
3