1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

baserCMSでhtmlメールをプラグインから送信するときに気をつけること

Last updated at Posted at 2020-01-29

追記

プルリクを送り、マージされました!!
https://github.com/baserproject/basercms/pull/1340
今後はhtmlメールを送るときに以下のことをやるのは必要ないです笑

問題

何回テストメールを送信しても

This email was sent using the CakePHP Framework, https://cakephp.org.
って挿入されて

ぐあああああああ

って思ってた今日この頃です。

↑をエンジニア向けに翻訳すると、
baserCMSのBcAppController->sendMail呼ぶときに、どうしてもcakePHPのデフォルトのレイアウトが読まれてしまってたのです

もともと、basercmsはhtmlメールに対応してないです。
いえ、正確に言えば対応してるんですけど↑のようになっちゃいます。
では、どうしたか。

解決法

シンプルです。
$optionで渡せばいいのです。

HogePlugin/Controller/HogeController
$options = [
	'Layout'		=> 'Hoge.default',
	'template'		=> 'Hoge.template',
	'format'		=> 'html',
];
$this->sendmail($to,$subject,$viewVars,$option);

僕の失敗はレイアウトを指定していなかったことが問題でした。
(もちろん参照元のレイアウトはプラグインフォルダ内に作ってくださいね!)

baserにhtmlメールのプルリク送ろうかなあ、、defaultのレイアウト作るだけやもんな

参考

https://qiita.com/materializing/items/9d7fe54435c9922a0472
https://book.cakephp.org/2/ja/core-utility-libraries/email.html#id6

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?