You want to receive email when your website has SQL error. You use Yii2 Framework to build your website. You don't know how to config it?
# Setup mailer
$config['components']['mailer'] = [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.huypv.net',
'username' => 'no-reply@huypv.net',
'password' => 'only_me',
'port' => '587',
'encryption' => '',
],
];
# Config log
$config['components']['log'] = [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\EmailTarget',
'levels' => ['error'],
'categories' => ['yii\db\*'],
'message' => [
'from' => ['no-reply@huypv.net'],# must be same username in mailer setup above
'to' => ['coder@huypv.net'],
'subject' => 'Database errors at huypv.net',
],
],
],
];