Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions addon.setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

return array(
'author' => 'Doug Black',
'author_url' => 'https://github.com/dougblackjr',
'docs_url' => 'https://github.com/dougblackjr/Email-From-Template',
'name' => 'RogEE Email-from-Template',
'description' => 'Add json-ld data to entry',
'version' => '2.0.0',
'namespace' => 'Email_from_template',
'settings_exist' => TRUE
);

/* End of file addon.setup.php */
4 changes: 0 additions & 4 deletions config.php

This file was deleted.

169 changes: 51 additions & 118 deletions pi.email_from_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@

*/

$plugin_info = array(
'pi_name' => "RogEE Email-from-Template",
'pi_version' => "1.5.0",
'pi_author' => "Michael Rog",
'pi_author_url' => "http://michaelrog.com/ee",
'pi_description' => "Emails enclosed contents to a provided email address.",
'pi_usage' => Email_from_template::usage()
);

/** ---------------------------------------
/** Email_from_template class
/** ---------------------------------------*/
Expand All @@ -38,42 +29,39 @@ class Email_from_template {
function Email_from_template($str = '')
{

$this->EE =& get_instance() ;

// defaults

$this->to = $this->EE->config->item('webmaster_email');
// defaults
$this->to = ee()->config->item('webmaster_email');
$this->cc = "";
$this->bcc = "";
$this->from = $this->EE->config->item('webmaster_email');
$this->subject = "Email-from-Template: ".$this->EE->uri->uri_string();
$this->from = ee()->config->item('webmaster_email');
$this->subject = "Email-from-Template: ".ee()->uri->uri_string();
$this->echo_tagdata = TRUE;
$this->append_debug = FALSE;

// params: fetch / sanitize / validate

$mailtype = (($mailtype = $this->EE->TMPL->fetch_param('mailtype')) == "html") ? "html" : "text";
$mailtype = (($mailtype = ee()->TMPL->fetch_param('mailtype')) == "html") ? "html" : "text";

$from = (($from = $this->EE->TMPL->fetch_param('from')) === FALSE) ? $this->from : $this->EE->security->xss_clean($from);
$to = (($to = $this->EE->TMPL->fetch_param('to')) === FALSE) ? $this->to : $this->EE->security->xss_clean($to);
$cc = (($cc = $this->EE->TMPL->fetch_param('cc')) === FALSE) ? FALSE : $this->EE->security->xss_clean($cc);
$bcc = (($bcc = $this->EE->TMPL->fetch_param('bcc')) === FALSE) ? FALSE : $this->EE->security->xss_clean($bcc);
$from = (($from = ee()->TMPL->fetch_param('from')) === FALSE) ? $this->from : ee()->security->xss_clean($from);
$to = (($to = ee()->TMPL->fetch_param('to')) === FALSE) ? $this->to : ee()->security->xss_clean($to);
$cc = (($cc = ee()->TMPL->fetch_param('cc')) === FALSE) ? FALSE : ee()->security->xss_clean($cc);
$bcc = (($bcc = ee()->TMPL->fetch_param('bcc')) === FALSE) ? FALSE : ee()->security->xss_clean($bcc);

$subject = (($subject = $this->EE->TMPL->fetch_param('subject')) === FALSE) ? $this->subject : $subject;
$alt_message = (($alt_message = $this->EE->TMPL->fetch_param('alt_message')) === FALSE) ? FALSE : $this->EE->security->xss_clean($alt_message);
$subject = (($subject = ee()->TMPL->fetch_param('subject')) === FALSE) ? $this->subject : $subject;
$alt_message = (($alt_message = ee()->TMPL->fetch_param('alt_message')) === FALSE) ? FALSE : ee()->security->xss_clean($alt_message);

$decode_subject_entities = (strtolower($this->EE->TMPL->fetch_param('decode_subject_entities')) == "no") ? FALSE : TRUE ;
$decode_message_entities = (strtolower($this->EE->TMPL->fetch_param('decode_message_entities')) == "no") ? FALSE : TRUE ;
$decode_subject_entities = (strtolower(ee()->TMPL->fetch_param('decode_subject_entities')) == "no") ? FALSE : TRUE ;
$decode_message_entities = (strtolower(ee()->TMPL->fetch_param('decode_message_entities')) == "no") ? FALSE : TRUE ;

$attachments = (($attachments = $this->EE->TMPL->fetch_param('attachments')) === FALSE) ? FALSE : $this->EE->security->xss_clean($attachments);
$attachments = (($attachments = ee()->TMPL->fetch_param('attachments')) === FALSE) ? FALSE : ee()->security->xss_clean($attachments);

$echo_tagdata = (strtolower($this->EE->TMPL->fetch_param('echo')) == "no" || strtolower($this->EE->TMPL->fetch_param('echo')) == "off") ? FALSE : TRUE ;
$echo_tagdata = (strtolower(ee()->TMPL->fetch_param('echo')) == "no" || strtolower(ee()->TMPL->fetch_param('echo')) == "off") ? FALSE : TRUE ;

// fetch tag data

if ($str == '')
{
$str = $this->EE->TMPL->tagdata ;
$str = ee()->TMPL->tagdata ;
}

$tagdata = $str;
Expand All @@ -88,154 +76,99 @@ function Email_from_template($str = '')
'cc' => $cc,
'bcc' => $bcc,
'subject' => $subject,
'ip' => $this->EE->input->ip_address(),
'httpagent' => $this->EE->input->user_agent(),
'uri_string' => $this->EE->uri->uri_string()
'ip' => ee()->input->ip_address(),
'httpagent' => ee()->input->user_agent(),
'uri_string' => ee()->uri->uri_string()
);

$variables[] = $single_variables;

$message = $this->EE->TMPL->parse_variables($tagdata, $variables) ;
$message = ee()->TMPL->parse_variables($tagdata, $variables) ;

// parse global variables

$subject = $this->EE->TMPL->parse_globals($subject);
$message = $this->EE->TMPL->parse_globals($message);
$subject = ee()->TMPL->parse_globals($subject);
$message = ee()->TMPL->parse_globals($message);

// decode HTML entities

if ($decode_subject_entities)
{
$this->EE->TMPL->log_item('Decoding HTML entities in subject...');
ee()->TMPL->log_item('Decoding HTML entities in subject...');
$subject = $decode_subject_entities ? html_entity_decode($subject) : $subject;
}

if ($decode_message_entities)
{
$this->EE->TMPL->log_item('Decoding HTML entities in message...');
ee()->TMPL->log_item('Decoding HTML entities in message...');
$message = $decode_message_entities ? html_entity_decode($message) : $message;
}

// mail the message

$this->EE->TMPL->log_item('Sending email from template...');
ee()->TMPL->log_item('Sending email from template...');

$this->EE->load->library('email');
$this->EE->email->initialize() ;
ee()->load->library('email');
ee()->email->initialize() ;

$this->EE->TMPL->log_item('MAILTYPE: ' . $mailtype);
$this->EE->email->mailtype = $mailtype;
ee()->TMPL->log_item('MAILTYPE: ' . $mailtype);
ee()->email->mailtype = $mailtype;

$this->EE->TMPL->log_item('FROM: ' . $from);
$this->EE->email->from($from);
ee()->TMPL->log_item('FROM: ' . $from);
ee()->email->from($from);

$this->EE->TMPL->log_item('TO: ' . $to);
$this->EE->email->to($to);
ee()->TMPL->log_item('TO: ' . $to);
ee()->email->to($to);

$this->EE->TMPL->log_item('CC: ' . ($cc ? $cc : '(none)'));
$this->EE->email->cc($cc);
ee()->TMPL->log_item('CC: ' . ($cc ? $cc : '(none)'));
ee()->email->cc($cc);

$this->EE->TMPL->log_item('BCC: ' . ($bcc ? $bcc : '(none)'));
$this->EE->email->bcc($bcc);
ee()->TMPL->log_item('BCC: ' . ($bcc ? $bcc : '(none)'));
ee()->email->bcc($bcc);

$this->EE->TMPL->log_item('SUBJECT: ' . $subject);
$this->EE->email->subject($subject);
ee()->TMPL->log_item('SUBJECT: ' . $subject);
ee()->email->subject($subject);

$this->EE->email->message($message);
ee()->email->message($message);

if ($alt_message !== FALSE)
{
$this->EE->email->set_alt_message($alt_message);
ee()->email->set_alt_message($alt_message);
}

if ($attachments !== FALSE)
{
$this->EE->TMPL->log_item('Adding attachemnts...');
ee()->TMPL->log_item('Adding attachemnts...');

$attachments_array = explode(",", $attachments);
foreach($attachments_array as $attachment_path)
{
$this->EE->TMPL->log_item('Attachment: '.$attachment_path);
$this->EE->email->attach($attachment_path);
ee()->TMPL->log_item('Attachment: '.$attachment_path);
ee()->email->attach($attachment_path);
}
}

$this->EE->email->Send();
ee()->email->Send();

// more template debugging

$this->EE->TMPL->log_item('Email sent!');
ee()->TMPL->log_item('Email sent!');

if (! $echo_tagdata) { $this->EE->TMPL->log_item('Echo is off. Outputting nothing to template.'); }
else { $this->EE->TMPL->log_item('Echo is on. Repeating message to template.'); }
if (! $echo_tagdata) { ee()->TMPL->log_item('Echo is off. Outputting nothing to template.'); }
else { ee()->TMPL->log_item('Echo is on. Repeating message to template.'); }

// return data to template

$this->return_data = ($echo_tagdata) ? $message : "";

if ($this->append_debug)
{
$this->return_data .= "<br><hr><br>".$this->EE->email->print_debugger();
$this->return_data .= "<br><hr><br>".ee()->email->print_debugger();
}

} // END Email_from_template() constructor
}

/** ----------------------------------------
/** Plugin Usage
/** ----------------------------------------*/

function usage()
{

ob_start();
?>

This plugin emails the enclosed content to a provided email address.

PARAMETERS:

from - sender email address (default: site webmaster)
to - destination email address (default: site webmaster)
cc - email addresses to carbon copy
bcc - email addresses to blind carbon copy
subject - email subject line (default: template URI)
mailtype - "text" or "html"
alt_message - a plain-text fallback for use with HTML emails
decode_subject_entities - Set to "no" if you don't want to parse the HTML entities in the subject line.
decode_message_entities - Set to "no" if you don't want to parse the HTML entities in the message text.
echo - Set to "off" if you don't want to display the tag contents in the template.

VARIABLES:

{to}
{from}
{subject}
{ip}
{httpagent}
{uri_string}

EXAMPLE USAGE:

{exp:email_from_template to="admin@ee.com" from="server@ee.com" subject="Hello!" echo="off"}

This tag content is being viewed at {uri_string}. Sending notification to {to}!

{/exp:email_from_template}

USING WITH OTHER PLUGINS AND TAGS:

When you want to email the output of other tags, put Email_from_Template INSIDE the other tag and use parse="inward" on the outer tags.

<?php
$buffer = ob_get_contents();

ob_end_clean();

return $buffer;

} // END usage()

} // END class Email-from-template
}

/* End of file pi.email-from-template.php */
/* Location: ./system/expressionengine/third_party/email-from-template/pi.email-from-template.php */
39 changes: 39 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Email From Template

This plugin emails the enclosed content to a provided email address.

## PARAMETERS:

from - sender email address (default: site webmaster)
to - destination email address (default: site webmaster)
cc - email addresses to carbon copy
bcc - email addresses to blind carbon copy
subject - email subject line (default: template URI)
mailtype - "text" or "html"
alt_message - a plain-text fallback for use with HTML emails
decode_subject_entities - Set to "no" if you don't want to parse the HTML entities in the subject line.
decode_message_entities - Set to "no" if you don't want to parse the HTML entities in the message text.
echo - Set to "off" if you don't want to display the tag contents in the template.

## VARIABLES:

{to}
{from}
{subject}
{ip}
{httpagent}
{uri_string}

EXAMPLE USAGE:

```
{exp:email_from_template to="admin@ee.com" from="server@ee.com" subject="Hello!" echo="off"}

This tag content is being viewed at {uri_string}. Sending notification to {to}!

{/exp:email_from_template}
```

## USING WITH OTHER PLUGINS AND TAGS:

When you want to email the output of other tags, put Email_from_Template INSIDE the other tag and use parse="inward" on the outer tags.