0

hi I am new to Expression engine I am getting total channel entries using EE Tag :-

{exp:stats channel="products" site="default_site"}{total_entries}{/exp:stats}

Now I want a email report that gives me total no of channel entries on daily basis I can use cron job but i want to know how to do this procedure.

0

First, make a hidden template, probably in template group called cron. For safety, you'll need to have some .htaccess rules that prevents anyone but your server from being able to reach this template. Then, in that template, turn on PHP. Here's an example to help (assuming a channel ID of 1):

<?php

// get number of products
$num_of_products = ee()->db->select()
                           ->from("channel_data")
                           ->where("channel_id", "1")
                           ->get()
                           ->num_rows();

// use the email class to send this information out
$email_msg = "Hello, we have {$num_of_products} today.";
$notify_address = "your@address.com";

ee()->load->library('email');

ee()->email->wordwrap = true;
ee()->email->mailtype = "text";
ee()->email->from("no-reply@address.com");
ee()->email->to($notify_address);
ee()->email->subject("Daily update");
// optional
// ee()->email->message(entities_to_ascii($email_msg));
ee()->email->message($email_msg);
ee()->email->Send();

?>

Then, using cron and curl, set a cron job to curl that address once a day. Remember to set .htaccess to deny access to that template file from any requester except self (127.0.0.1). Now you can use addons like PostMaster to make this whole process much easier, but you have to purchase them. I'm giving you a raw but free answer.

| improve this answer | |
  • I have postmaster addon please tell me how to do this job with that and i want to send only daily channel entries not total. – Abhay Oct 22 '15 at 5:12

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.