$email = new CakeEmail('default'); --> ここでtoやfrom、本文(template)などを指定 <--
最後に
return $email->send();
しています。
send()は、lib\Cake\Network\Email\CakeEmail.php にあり、
public function send($content = null) { if (empty($this->_from)) { throw new SocketException(__d('cake_dev', 'From is not specified.')); } if (empty($this->_to) && empty($this->_cc) && empty($this->_bcc)) { throw new SocketException(__d('cake_dev', 'You need to specify at least one destination for to, cc or bcc.')); } if (is_array($content)) { $content = implode("\n", $content) . "\n"; } $this->_message = $this->_render($this->_wrap($content)); $contents = $this->transportClass()->send($this); if (!empty($this->_config['log'])) { $config = array( 'level' => LOG_DEBUG, 'scope' => 'email' ); if ($this->_config['log'] !== true) { if (!is_array($this->_config['log'])) { $this->_config['log'] = array('level' => $this->_config['log']); } $config = $this->_config['log'] + $config; } CakeLog::write( $config['level'], PHP_EOL . $contents['headers'] . PHP_EOL . $contents['message'], $config['scope'] ); } return $contents; }
こうなっています。
なんやかんやで一応処理はしているようなので、
$email = new CakeEmail('default'); Try { return $email->send(); }catch(Exception $e{ --> ここでエラー時用のtoやfrom、本文(template)などを指定 <-- }
Q1
これで問題ないですか?何か懸念点がありますか?
単純にsendされたときにエラーが起きれば、で判定したいのでsendをtryで括ったんですが。
Q2
また、
https://norm-nois.com/blog/archives/2865
このサイトに書いてあることはどういった場合に有効なんでしょうか?
私のやり方とどう違いますか?
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/07/13 02:29
退会済みユーザー
2021/07/13 03:02 編集
2021/07/13 02:54