<?
include('Mail.php');
include('Mail/mime.php');
// Setup some variables
$cpusername = 'accountname'; //Your cPanel user name
$cppassword = 'accountpassword'; // Your cPanel password
$domainName = 'mydomain.com'; // Your domain name (no 'www')
$sender = '[email protected]'; // Your email address
$recipient = 'Whatever <[email protected]>'; // The Recipients name and email address
$baseURL = 'http://www.mydomain.com'; // Your base URL
$smtphost = 'mail.mydomain.com'; // 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]http://www.mydomain.com[/url], the awstats images are located at
[url]http://www.mydomain.com/images/awstats[/url]
*/
//$baseURL = 'http://www.hostedpro.com';
/*****************************************
You probably don't have to edit below here
*****************************************/
$hostname = "http://$cpusername:$cppassword@$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/awstats.pl?config=$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;
}
$i++;
}
fclose($fp);
// 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
$mime->setHTMLBody($html);
// 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!");
}
else
{
echo("Your message was not sent: " . $result);
}
?>