0

I'm trying to create a plugin to greet depends on the time of a day with a different phrase.

The plugin works correctly on the ExpressionEngine environment but at the moment is not able to send any data parsed, rather than plain text in my email.

My email works with a plugin (user) which use the default email for expressionengine to send an email like so:

        ee()->email->wordwrap = true;
        ee()->email->from(
            ee()->config->item('webmaster_email'),
            ee()->config->item('webmaster_name')
        );
        ee()->email->to($email_data['to']);
        ee()->email->subject($email_subject);
        ee()->email->message($email_template);
        ee()->email->send();

My plugin instead looks like that:

class Time_greeting {

    public $greetings = "";

    public function greeting()
    {

        $ee = $this->EE =& get_instance();

        $tagdata = $ee->TMPL->tagdata;

        $time = date("H");
        $timezone = date("e");
        if ($time < "12") {
            $greetings = "Good morning";
        } else
        if ($time >= "12" && $time < "17") {
            $greetings = "Good afternoon";
        } else
        if ($time >= "17" && $time < "19") {
            $greetings = "Good evening";
        } else
        if ($time >= "22") {
            $greetings = "Good night";
        }
        return $greetings;
    }
}

And I'm calling it in a template like that:

{exp:time_greeting:greeting} {name},

To reset your password, please go to the following page:

{reset_url}

As you can expect, it works fine inside ExpressionEngine in any template.

Is there any way to parse the plugin before sending the email so I can get a phrase like I explained?

  • User - from EE Harbour? I think you will need to speak to them about how you can hook it into their custom plugins code. I have done this via Hooks for freeform, etc. so hopefully EE Harbour can advise. – Nevsie - Modeten Mar 14 '18 at 17:22
0

You can use template text to send email, And you can put your variables within Curley braces. And you can replace those with your dynamic values inside your plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.