CI4 How to create and choose between two types of email configurations - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: CI4 How to create and choose between two types of email configurations (/showthread.php?tid=81326) |
CI4 How to create and choose between two types of email configurations - serialkiller - 02-16-2022 How can I send an email with the default configuration (Config\Email) and immediately afterwards send a second one with another configuration (Config\Email2) and finally restore the default one? RE: CI4 How to create and choose between two types of email configurations - InsiteFX - 02-17-2022 You need to create two seperate configs for the email. CodeIgniter 4 User Guide - Setting Email Preferences PHP Code: $email->initialize($config1); That should get you going. RE: CI4 How to create and choose between two types of email configurations - serialkiller - 02-17-2022 (02-17-2022, 01:38 AM)InsiteFX Wrote: You need to create two seperate configs for the email. I have already created the two configuration files for it, so should I do this? PHP Code: $config1 = config('Email1'); Doing so, however, gives me this error Cannot use object of type Config\Email1 as array RE: CI4 How to create and choose between two types of email configurations - paulbalandan - 02-17-2022 Email::initialize() accepts object instance of Config\Email or array as argument. From the error it seems you are passing neither an array or Config\Email instance. Two possible solutions: 1) Config\Email1 and Config\Email2 should extend Config\Email. So, retain the original Config\Email provided by the framework. Then, in each Email1 and Email2, class Email1 extends Email {} // instead of extends BaseConfig class Email2 extends Email {} // instead of extends BaseConfig 2) Use `get_object_vars` $email->initialize(get_object_vars($config1)); $email->initialize(get_object_vars($config2)); RE: CI4 How to create and choose between two types of email configurations - serialkiller - 02-18-2022 (02-17-2022, 08:51 PM)paulbalandan Wrote: Email::initialize() accepts object instance of Config\Email or array as argument. From the error it seems you are passing neither an array or Config\Email instance. Perfect, thanks |