Welcome Guest, Not a member yet? Register   Sign In
Best practice Send Mail
#1

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 ?
Reply
#2

(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();

//then any of the methods can be used by:

$utilityHandle->method();
Thats not a massive amount of code and of course you can feed in paramters(appropriate to the method such as


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';
                            $mail->Port = 587;
                            $mail->SMTPSecure = 'tls';        
                            $mail->SMTPAuth = true;

In any controller , you will have a small method that only needs a couple of lines .
CMS CI4     I use Arch Linux by the way 

Reply




Theme © iAndrew 2016 - Forum software by © MyBB