Controller\Admin\Mailer::update PHP Method

update() public method

更新 邮件系统设置
public update ( )
    public function update()
    {
        $result['error'] = 0;
        $result['message'] = '保存完成';
        foreach ($_POST as $key => $val) {
            if (!empty($val) && strpos($key, 'mail_') !== false) {
                if (strpos($key, 'mailer') === false) {
                    // 判断是否为 mail_mailer <- 这个字段是用于是被当前设定的邮件类名,此配置无需存入数据库
                    $k = str_replace('mail_', '', $key);
                    $data[$k] = trim($val);
                }
            }
        }
        if (!empty($_POST['mail_mailer'])) {
            $config = json_encode($data);
            $mailer = trim($_POST['mail_mailer']);
            Option::set('MAIL_' . $mailer, $config);
            Option::set('MAIL_AVAILABLE', $mailer);
        } else {
            $result['error'] = 1;
            $result['message'] = '保存失败,参数不完整';
        }
        Option::init();
        return $result;
    }