public function saveSubmission(Submission $submission)
    {
        $contactFormSubmission = new ContactFormSubmission();
        $contactFormSubmission->form = $submission->message['formName'] ?? 'contact';
        $contactFormSubmission->fromName = $submission->fromName;
        $contactFormSubmission->fromEmail = $submission->fromEmail;
        $contactFormSubmission->subject = $submission->subject;

        if (!is_array($submission->message)) {
            $submission->message = ['message' => $this->utf8Value($submission->message)];
        }

        $message = $this->utf8AllTheThings($submission->message);
        $contactFormSubmission->message = json_encode($message);

        if (Craft::$app->elements->saveElement($contactFormSubmission)) {
            return $contactFormSubmission;
        }

        throw new Exception(json_encode($contactFormSubmission->errors));
    }
public function saveSubmission(Submission $submission)
    {
        $contactFormSubmission = new ContactFormSubmission();
        $contactFormSubmission->form = $submission->message['formName'] ?? 'contact';
        $contactFormSubmission->fromName = $submission->fromName;
        $contactFormSubmission->fromEmail = $submission->fromEmail;
        $contactFormSubmission->subject = $submission->subject;

        if (!is_array($submission->message)) {
            $submission->message = ['message' => $this->utf8Value($submission->message)];
        }

        $message = $this->utf8AllTheThings($submission->message);
        $contactFormSubmission->message = json_encode($message);

        if (Craft::$app->elements->saveElement($contactFormSubmission)) {
            return $contactFormSubmission;
        }

        throw new Exception(json_encode($contactFormSubmission->errors));
    }
public function saveSubmission ( Submission $ submission ) { $ contactFormSubmission = new ContactFormSubmission ( ) ; $ contactFormSubmission -> form = $ submission -> message [ 'formName' ] ?? 'contact' ; $ contactFormSubmission -> fromName = $ submission -> fromName ; $ contactFormSubmission -> fromEmail = $ submission -> fromEmail ; $ contactFormSubmission -> subject = $ submission -> subject ; if ( ! is_array ( $ submission -> message ) ) { $ submission -> message = [ 'message' => $ this -> utf8Value ( $ submission -> message ) ] ; } $ message = $ this -> utf8AllTheThings ( $ submission -> message ) ; $ contactFormSubmission -> message = json_encode ( $ message ) ; if ( Craft :: $ app -> elements -> saveElement ( $ contactFormSubmission ) ) { return $ contactFormSubmission ; } throw new Exception ( json_encode ( $ contactFormSubmission -> errors ) ) ; }
This function can literally be anything you want, and you can have as many service
functions as you want.

From any other plugin file, call it like this:

CraftContactFormExtensions::$plugin->craftContactFormExtensionsService->exampleService()

@param Submission $submission

@throws Exception
@throws \Throwable
@throws \craft\errors\ElementNotFoundException

@return mixed
This function can literally be anything you want and you can have as many service functions as you want .