Welcome Guest, Not a member yet? Register   Sign In
Outbox: Email management
#1

(This post was last modified: 10-26-2020, 01:02 PM by MGatner.)

Hi friends- This one has actually been out for a while but I didn't post it originally. A major new feature goes live today so I thought I would share:

Tatter\Outbox
Email toolkit for CodeIgniter 4
https://github.com/tattersoftware/codeigniter4-outbox

This is a bundle of supplemental tools to help make using CI4's Email class a little easier. Major features include:
1. Email Logging - Defines an Event listener triggered on Email:Confusedend and logs email content to the database
2. Inlining - Adds CSS-inlining to email bodies, to make it easy to incorporate your site's CSS or any custom CSS you want into an HTML email to help it look snazzy.
3. Tokens - Uses {tokens} with the View Parser to let you swap content out for bulk email needs
4. Templating - With tokens and inlining, templates let you define as many prearranged email templates in the database to be sent at any time. The module includes its own MVC for this so it is easy to add to any application.

Quick Start
* Install with Composer: > composer require --dev tatter/outbox
* Migrate the database: > php spark migrate -all
* Define the template routes in app/Config/Routes.php (if you want to use them)

Find the package on Packages: https://packagist.org/packages/tatter/outbox
Add issues and requests on GitHub: https://github.com/tattersoftware/codeigniter4-outbox
Reply
#2

Checking...
Thanks @MGatner

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply
#3

Hi,

Thanks for your contribution. I've installed this via composer as suggested, I'm currently building a system on Ci4 with an admin dashboard all within the URL route of 'admin'. Obviously, the Views files within the package contain URLs to work from the root.

My question is; if I choose to use a module like this and then need to override the template files so I can adjust links and HTML markup to match the admin theme what is the best way to do this?

I've not done a great deal in this area so could be missing somethings obvious.

Thanks in advance.
Reply
#4

Just follow the instructions to add your own configuration file, and then set the $layout property. Here is a project where I do exactly what you are describing:
https://gitlab.oit.duke.edu/academic-tec...Outbox.php
Reply
#5

(This post was last modified: 02-05-2021, 05:23 AM by thewebsiteguy.)

Hi,

I've been using Outbox successfully recently but I've just come to add extra functionality to my system and have an issue.

I've created a helper function that I pass all the details to so I can send an email. My Ci4 is now set to use SMTP with multiple profiles pulled from a database table.

My issue is that I can't get the initialize option to work in conjunction with Outbox, see my function below. I've tried both the array and object and neither work as expected. With the '$email->initialize($config);' in the location is it the system sends a blank email with no subject etc, if I move the '$email->initialize($config);' line to just above the send line then nothing gets sent and no error is logged/returned.

PHP Code:
<?php

use App\Models\DataModel;
use 
Tatter\Outbox\Models\TemplateModel;

if (!
function_exists('mail_send')) {

    function mail_send($data$template$site$to$attachments null$cc null$bcc null)
    {
        if(is_numeric($site)) {
            
$site DataModel::getWebsite($site);
        } elseif(
is_array($site)){
            $site = (object)$site;
        }
        
        $config 
= new \Config\Email;
        $config->protocol 'smtp';
        $config->SMTPHost $site->smtp_host;
        $config->SMTPUser $site->smtp_username;
        $config->SMTPPass $site->smtp_password;
        $config->SMTPPort $site->smtp_port;
        $config->SMTPCrypto $site->smtp_protocol;
        
        
//$config = [];
        //$config['protocol'] = 'smtp';
        //$config['SMTPHost'] = $site->smtp_host;
        //$config['SMTPUser'] = $site->smtp_username;
        //$config['SMTPPass'] = $site->smtp_password;
        //$config['SMTPPort'] = $site->smtp_port;
        //$config['SMTPCrypto'] = $site->smtp_protocol;
        
        $outbox 
model(TemplateModel::class)->findByName($template);
    
    $email $outbox->email($data);
        $email->initialize($config);
        
        $email
->setFrom($site->email_from_address$site->email_from_name$site->email_from_return);
    
    $email->setTo($to);
        if(is_null($attachments) == false) { 
            foreach($attachments as $attachment) {
                $email->attach($attachment);
            }
        }
        if(is_null($cc) == false) {
            $email->setCC($cc);
        }
        if(is_null($bcc) == false) {
            $email->setBCC($bcc);
        }

    
    if($email->send()) {
            return TRUE;
        } else {
            $email->printDebugger(['headers']);
            return FALSE;
        }
    }

Reply
#6

When you call `$outbox->email($data)` it will create a pre-initialized version of the Email service class for you. Re-calling `initialize()` will override any configuration set by the template. You should remove the `initialize()` line, and it there are additional configuration parameters you need then set them on the resultant Email instance directly.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB