Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sorinr's avatar

Multiple config/mail.php

Hi,

I'm working on an web app using Laravel 5 framework that has to send emails but dynamically using different configurations.

I have set up a table with all needed smtp server details for each configuration.

My question is: Can the users in the same time send emails using a certain configuration retrieved from the smtp details table that will dynamically override the default mail config?

Thank you all in advance for your help.

0 likes
7 replies
sorinr's avatar

Thnx absiddiqueLive,

There is no doubt that I'll have to handle it manually, but the question still remains, if in production this thing will work appropriately?.

Unfortunately, as a lone developer I can't figure out how I can test a multi environment situation.

Writing a test Controller to try to simulate the multi environments its a loose of time because all the commands are running sequentially not in the same time.

If you have any other idea I would greatly appreciate.

sorinr's avatar

Hi,

I've already saw that article but I still can't get the idea how I can concurrently make changes to only one config mail file.

According to Laravel 5 documentation regarding configuration I can use Config::set('mail.host', 'mysmtp.host.com'); and all of data needed for configuration that I can retrieve from a database table.

The problem starts when more users are trying to actually change the config/mail.php file maybe in the same time. What is going to happen?

For better understanding I'll explain the real situation:

  1. One user (read it as employee) it's working today in one shop, tomorrow in another one and so on;
  2. Each Shop has an own e-mail address but one shop has an account opened with gmail, another one with hotmail, etc.

All users are going to use the same app but when they are sending emails from that location I want the emails to be sent through the according services gmail, hotmail, etc but with the credentials of that particular account (location).

Hope someone reading this post will be able to give some idea how can I handle this.

Thanks

Hipe's avatar

Planning to do something like that aswell, maybe the same way that I handled each user having it's language (either by cookie if not logged in or by session if logged in) like... in every route you're going to use the email use a middleware. This middleware checks what email to use ( like, if user is working on shop id 2 use that email etc) and sets it, and then the function is called and email sent. Next person sending the e-mail will go through the same middleware and such. The problem is that queueing an email may be a little bit harder. I'll try to implement this and then come back here with results ^^

MikeHopley's avatar

Perhaps config isn't the best place for this?

User-dependent "config" could be stored in a database instead (or even a key-value store, like Redis).

Please or to participate in this conversation.