Best practice Send Mail |
Hi , if i have several control to send the same mail wich is the best way to do this ? a method in every controller or ?
09-24-2022, 01:29 AM
(This post was last modified: 09-24-2022, 01:31 AM by captain-sensible. Edit Reason: elaborated a little )
I have a class called Utility.php ; funny enough as you might guess it does stuff like checking submitted text from a form by users for spam. The class is located in a directory called Andy and that directory, with its classes is in the app directory of CI4 ; and so in any controller i reference it by:
Code: use \App\Andy\Utility; The Utility class has several methods and any controller can use them. Its done by simply creating an instance of the class in any other Controller or other class using: Code: $utilityHandle= new Utility(); Code: $utilityHandle->method($parem1, $parem2); So there's probably other approaches but; i'm thinking create a class that does all the heavy lifting such as using SMTP and password creds, etc This kind of stuff Code: $mail->Host = 'smtp.xxxx.com'; In any controller , you will have a small method that only needs a couple of lines . |
Welcome Guest, Not a member yet? Register Sign In |