We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Simple Plugin Not Working - I can't see why - Help please?

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Just wondering if someone can show me the error of my ways on this one?

I have a very simple plugin (code shown below) which when called in a template using this code :

{exp:admin_email redirect="template_group/template"}

I was hoping that it would first send the email and then secondly redirect to the redirect=”template_group/template” template that is set in the plugin parameter.

I’m not getting the e-mail sent and not getting the re-direct happening either. If I take out all the email sending part though the plugin does redirect to the other template so I know that bit’s working.

Anyone know why the email sending part wouldn’t be working though?

<?php

/*
=========================================================================
 Copyright (c) 2008 Mark Bowen Design
=========================================================================
 File: pi.admin_email.php V1.0
-------------------------------------------------------------------------
 Purpose: Send admin an email
=========================================================================
CHANGE LOG :

18th September 2009
    - Version 1.0
    - Creation of initial plugin
=========================================================================
*/


$plugin_info = array(
  'pi_name' => 'Admin Email',
  'pi_version' => '1.0',
  'pi_author' => 'Mark Bowen',
  'pi_author_url' => 'http://www.markbowendesign.com/',
  'pi_description' => 'Send an email to the admin',
  'pi_usage' => Admin_email::usage()
  );

class Admin_email
{

    var $return_data = "";

    function Admin_email()
    {
        global $TMPL, $DB, $SESS, $FNS;
        $tagdata = $TMPL->tagdata;

        // Set up a few constants
        $member_id = $SESS->userdata['member_id'];
        $redirect = $TMPL->fetch_param('redirect');

$recipient = "[email protected]";
$from = "[email protected]";
$email_subject = "Email Subject";
$email_msg = "This is the body content of the email";

if ( ! class_exists('EEmail'))
{
    require PATH_CORE.'core.email'.EXT;
}

$email = new EEmail;
$email->wordwrap = true;
$email->mailtype = 'text';
$email->from($from);
$email->to($recipient);
$email->subject($email_subject);
$email->message($REGX->entities_to_ascii($email_msg));
$email->Send();


            $redirect = $FNS->create_url($redirect);
            $FNS->redirect($redirect);


//            $this->return_data .= $tagdata;
    }
 
  // ----------------------------------------
  //  Plugin Usage
  // ----------------------------------------

  // This function describes how the plugin is used.
  //  Make sure and use output buffering

  function usage()
  {
  ob_start(); 
  ?>


<?php
  $buffer = ob_get_contents();
    
  ob_end_clean(); 

  return $buffer;
  }
  // END

}


/* End of file pi.admin_email.php */
/* Location: system/plugins/pi.admin_email.php */

Thanks for any help on this.

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Any of the moderators possibly want to show me the error of my ways maybe? 😉

Unless I’m being completely blind (probably the case ;- ) ) I’m pretty sure I just copied the email part from the documentation exactly as it was but it just doesn’t seem to want to work. If I however place a standard PHP mail() function in there instead then I get the e-mail so I’m a little confused as to what I’m doing wrong here.

       
silenz's avatar
silenz
1,651 posts
16 years ago
silenz's avatar silenz

$REGX is missing in the list of globals. Other than that it should work.

global $TMPL, $DB, $SESS, $FNS, $REGX;
       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen
$REGX is missing in the list of globals. Other than that it should work.
global $TMPL, $DB, $SESS, $FNS, $REGX;

Eek!! That’s what you get from staring at something for WAAAAAY too long!! 😊

Thanks for that. Will give it a go now.

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Worked immediately upon adding in the $REGX global, thanks tons!

I guess that’s what you get for trying something out at 4 in the morning!! 😊

Best wishes,

Mark

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.