Awstats reports via email


Well-Known Member
Sep 19, 2008
I have a client that would like to view his awstats info. However the user is a little, well 'clueless' and is as likely as not to delete his entire site if given access to his cpanel.

So - is there any way to get the awstats reports emailed on a regular basis ?


Well-Known Member
Sep 19, 2008
Seems a fair bit of discussion in those threads but no solutions. I've seen some threads on other sites regarding custom scripts but am naturally reluctant to use such scripts without knowing what else they might do !


Staff member
Apr 11, 2011
The only manual workarounds I have seen have been in regards to viewing the interface without cPanel access, as opposed to emailing data from Awstats to specific users. There are links to these workarounds in the thread mentioned in my last response. You may want to add your feedback and vote for that feature request to encourage it's implementation so a supported solution is available.

Thank you.


Jan 14, 2014
cPanel Access Level
Website Owner
I have two websites on an inexpensive shared hosting account with cPanel, a personal site and a business site. I probably will go with Google Analytics for the business site, but that's too intrusive for my personal site, which is just for hosting articles I wrote. Awstats is exactly what I need for the personal site. However, I'm so busy that I rarely remember to periodically check my awstats for the personal site. If I could have a report emailed to me every two weeks, that would be ideal. Just being able to see the report without logging in is only half the solution; I'd also want the report pushed to me periodically.

If the link to the awstats page were static then I could probably whip up a simple script to generate and email such a report myself, but the URL seems to include a session ID in the middle, which makes that idea sound much too complicated to be worthwhile. I imagine the dynamic link is a security precaution.


Sep 8, 2006
East Texas
cPanel Access Level
Root Administrator
Hi Folks, just bumping this old thread...

I've been using a script for this for years. I keep the script in the root so it's not publicly accesible and I copy all the aw images to the public images dir. Just changes the variables & run it through cron. Here's the script.


// Setup some variables
$cpusername = 'accountname';                         //Your cPanel user name
$cppassword = 'accountpassword';                     // Your cPanel password
$domainName = '';                 // Your domain name (no 'www')
$sender = '[email protected]';                  // Your email address
$recipient = 'Whatever <[email protected]>';         // The Recipients name and email address
$baseURL = '';          // Your base URL
$smtphost = '';               // Your outbound (SMTP) mail server (MTA)
$smtpport = '25';                             // Your SMTP post (usually 25, could be different)
$smtpauth = true;                             // This should always be set to true
$smtpuname = '[email protected]';                // Your SMTP username
$smtppass = 'smtpuserpassword';                       // Your SMTP password

// Don't edit anything in the following function
Function get_stats()
	global $cpusername, $cppassword, $domainName, $baseURL;

	//$printOutput = 0;     // set to 0 if you do not want the script to output anything (eg for use with a cron job)

	/*     Enter your base url below:
    eg. if you baseURL is [url][/url], the awstats images are located at
	//$baseURL = '';

	You probably don't have to edit below here

	$hostname = "http://$cpusername:[email protected]$domainName:2082";
	$day = date('j');
	$month = date('F');
	$year = date('Y');
	$subject = "$month $day, $year Web Site Statistics for $domainName";
	$month = date('m')-0;
		if (!(@$fp = fopen("$hostname/$domainName&lang=en&framename=mainright&update=1", 'r'))) {
    		if ($printOutput == 1) die("<strong>Error opening statistics file.</strong>");
    			else exit();

	//file opened successfully if we have reached here
	$i = 1;
	$body = "";
	while (!feof($fp)) {
		$chunk = fgets($fp); // Read file line by line
	if ($i == 5) { // Add html code to head section
		$body .= '<base href="' . $baseURL . '">';
	if (($i <= 47) || $i >= 90) {
		// Save line contents
		$body .= $chunk;

	// Remove all links in the HTML file received:
	$body = preg_replace("/<a(.*?)a>/i", "", $body);

	return $body;
// End function
// Constructing the email
// Building the subject line
$day = date('j');
$month = date('F');
$year = date('Y');
$subject = "$month $day, $year Web Site Statistics for $domainName";	// Subject for the email
$html = get_stats();      // Grabs the AWS data from the function for the body
$crlf = "\n";
$headers = array(
	'From'          => $sender,
	'Return-Path'   => $sender,
	'To'			=> $recipient,
	'Subject'       => $subject

// Creating the Mime message
$mime = new Mail_mime($crlf);

// Setting the body of the email

// Set body and headers ready for base mail class
$body = $mime->get();
$headers = $mime->headers($headers);

// SMTP authentication params
$smtp_params["host"]     = $smtphost;
$smtp_params["port"]     = $smtpport;
$smtp_params["auth"]     = $smtpauth;
$smtp_params["username"] = $smtpuname;
$smtp_params["password"] = $smtppass;

// Sending the email using smtp
$mail =& Mail::factory("smtp", $smtp_params);
$result = $mail->send($recipient, $headers, $body);
	if($result == 1)
		echo("Your message has been sent!");
		echo("Your message was not sent: " . $result);

I forget know where I found the original code or I'd give credit, it was many years ago.

You do have to install the Mail & Mail_Mime PEAR packages but that's easy enough though WHM. The AW images need to me copied from the 3rdparty dir (or download new) & setup with proper ownership & permissions.

My problem right now is that I setup a new cloud server for a client that was growing out of shared hosting and I can't get the page to send. I can see the php fire in a cron report but no love on the report. It seems to fail silently.

Hope this helps someone and I hope it's not a huge security risk, I've never had a hack on it.

Any ideas on why it's not working on the cloud server, please let me know. IT's working on other servers I have it on and I can't seem to find differences in configurations between them.