# Overriding Mail service

**URL:** <https://forums.concretecms.org/t/overriding-mail-service/9060>\
**Category:** Developing with Concrete\
**Created:** [May 10, 2025, 8:19pm UTC](https://forums.concretecms.org/t/overriding-mail-service/9060 "2025-05-10T20:19:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsorelle](https://forums.concretecms.org/user_avatar/forums.concretecms.org/tsorelle/32/6246_2.png) [@tsorelle](https://forums.concretecms.org/u/tsorelle)\
**Post date:** [May 10, 2025, 8:19pm UTC](https://forums.concretecms.org/t/overriding-mail-service/9060/1 "2025-05-10T20:19:30Z")

</div>

In an earlier version of concreteCMS, I did a successful override of the mail service by creating a custom class based on Concrete\Core\Mail\Service. I registered this with a version of MailServiceProvider containing

```auto
       $register = [
            'helper/mail' => '\Tops\concrete5\services\TopsMailService',
            'mail' => '\Tops\concrete5\services\TopsMailService',
        ];

```

TopsMailService simply inserted some code in the SendMail() method.  
It worked fine and still works under newer ConcreteCMS versions.  
However, wanting to play nice with core, I rewrote it based on the new latest version of the Mail\Service class.

The biggest difference I could see was that the new version has use statements for Laminas\Mail classes where the old version has Zend\Mail references. If I replace these use statements, I get the exception

```auto
Illuminate \ Contracts \ Container \ BindingResolutionException
Target [Laminas\Mail\Transport\TransportInterface] is not instantiable while building [\Tops\concrete5\services\TopsMailService].

```

Huh?

My old custom class still works perfectly, but I am concerned about future compatibility and well, just good practices.

Can anyone suggest a better way to do the override or any modification I could make to avoid the exception. I’ll upload code if anyone is interested.

Another thought, Since I am trying to override the actual method of sending the message (not the message construction) maybe I should try to override the transport class, rather than the service. Not sure how to do that. Any thoughts would be welcome.

---

<div class="post-metadata">

**Author:** ![tsorelle](https://forums.concretecms.org/user_avatar/forums.concretecms.org/tsorelle/32/6246_2.png) [@tsorelle](https://forums.concretecms.org/u/tsorelle)\
**Post date:** [May 11, 2025, 9:39pm UTC](https://forums.concretecms.org/t/overriding-mail-service/9060/2 "2025-05-11T21:39:13Z")

</div>

I have resolved the problems of the dependency on Lamina or Zend for now. I am still wondering if overriding the transport would be a better approach and would appreciate comments.

---

<div class="post-metadata">

**Author:** ![hissy](https://forums.concretecms.org/user_avatar/forums.concretecms.org/hissy/32/5107_2.png) [@hissy](https://forums.concretecms.org/u/hissy)\
**Post date:** [May 12, 2025, 1:41am UTC](https://forums.concretecms.org/t/overriding-mail-service/9060/3 "2025-05-12T01:41:39Z")

</div>

It’s better to show your Concrete version

---

<div class="post-metadata">

**Author:** ![tsorelle](https://forums.concretecms.org/user_avatar/forums.concretecms.org/tsorelle/32/6246_2.png) [@tsorelle](https://forums.concretecms.org/u/tsorelle)\
**Post date:** [May 12, 2025, 11:11am UTC](https://forums.concretecms.org/t/overriding-mail-service/9060/4 "2025-05-12T11:11:26Z")

</div>

Thanks hissy, and sorry I forgot to indicate my environment details. ConcreteCMS 9.3.9. PhP 8.2. Database 10.6-MariaDB. As I mentioned in the reply, I have resolved the Lamina/Zend dependency issue and no longer get any exceptions. My urgency is passed, but I’m still interested in any opinions and suggestions of better practice to override mail sending.

---

<div class="post-metadata">

**Author:** ![tsorelle](https://forums.concretecms.org/user_avatar/forums.concretecms.org/tsorelle/32/6246_2.png) [@tsorelle](https://forums.concretecms.org/u/tsorelle)\
**Post date:** [May 13, 2025, 4:35pm UTC](https://forums.concretecms.org/t/overriding-mail-service/9060/5 "2025-05-13T16:35:11Z")

</div>

Here’s the latest on this. All is working fine now except I get a creepy feeling that my solution is not the best practice. Any advice is welcome. Here are more details.

I overrode the mail provider class in application\config\app.php:

```auto
return [
    'providers' => array(
       'core_mail' => '\Application\providers\TopsMailServiceProvider'
    )];

```

In the provider I registered the mail service:

```auto
        $app = $this->app;
        $register = [
            'helper/mail' => '\Tops\concrete5\services\TopsMailService',
            'mail' => '\Tops\concrete5\services\TopsMailService',
        ];

```

The exception I mentioned earlier occurs if there is any reference to Laminas classes. Since I am using my own mailing service I removed all references to Laminas in both classes and all works fine, at least for my purposes.

What I wonder is:

1. Should I use a different method or location to register and instantiate the mail service? I guess that the reason for the exception was that Laminas and my service were instantiated in the wrong order.
2. Would it have been a better approach to try to override the transport class?
3. Any other ideas?

Thanks to all.
