Generate an e-mail on page-not-found (404) errors [support thread]
I got tired of scouring my Apache logs for 404 errors, so wrote this little update that will send an e-mail to the address of your choice as part of the page_not_found processing.
Installation is short and simple (see the readme). You'll need to edit /includes/languages/english/YOURTEMPLATE/page_not_found.php to contain your desired e-mail address.
See download here: http://www.zen-cart.com/downloads.php?do=file&id=1090
Re: Generate an e-mail on page-not-found (404) errors
If you have a Google WebmasterTools account, there's a neat little report in there listing all the URLs that Google finds as 'not found' and all the pages that have those links on.
Most of the time, the list will contain URLs for removed products, but it's worth a scan every now and again.
Re: Generate an e-mail on page-not-found (404) errors
Thanks for the info, g1smd. My focus for developing this little add-on was more to get a notification for accesses that are likely someone groping around my site, of the like
www.example.com/admin
... when I've followed the security guidelines and renamed that folder.
Re: Generate an e-mail on page-not-found (404) errors
OK. That works too. :smile:
Additionally, I like to add this in the .htaccess file in the /admin/ folder:
Code:
Order Deny,Allow
Deny from all
Allow from 11.22.33
which allows access from a small range of IP addresses.
Re: Generate an e-mail on page-not-found (404) errors
Oops! There was an error in the first release (the observer class was not being instantiated).
I've just uploaded v1.1 to correct the error in class.emailFor404.php from
Code:
function emailFor404() {
if (SEND_404_ERRORS_EMAIL_TO_STATUS == '1' and SEND_404_ERRORS_EMAILS_TO != '') {
$this->attach($this, array('NOTIFY_HEADER_END_PAGE_NOT_FOUND'));
}
}
to
Code:
function emailFor404() {
global $zco_notifier;
if (SEND_404_ERRORS_EMAIL_TO_STATUS == '1' and SEND_404_ERRORS_EMAILS_TO != '') {
$zco_notifier->attach($this, array('NOTIFY_HEADER_END_PAGE_NOT_FOUND'));
}
}
Re: Generate an e-mail on page-not-found (404) errors
The $this-> approach will work fine in 1.3.9 and newer.
For 1.3.8 and older you may have to use the old $zco_notifier-> approach instead.
Email on 404 (page-not-found) errors [support thread]
I've updated this add-on to v1.2 (http://www.zen-cart.com/downloads.php?do=file&id=1090), including a switch to enable/disable the archiving of these emails.
email body text not included in email
Hi,
Just tried out this latest version on ZC 1.5.
I receive the email but the text is not passed, its always:
Quote:
A 404 Error Was Generated
$EMAIL_MESSAGE_HTML
Strangely the email is in html format irrespective of the format chosen in the admin.
I get the same results with an (almost) vanilla 1.5 installation.
It tried it local/Xampp and remote hosting, same result.
regards
Steve
Re: email body text not included in email
I'm having a devil of a time replicating this. I've tried changing my CHARSET to utf-8 (which I'm assuming you're using), tried running as a logged-in or guest customer, changing my admin email format from HTML to Text and back. Regardless of these settings, I'm always receiving a Text-format message:
Code:
A user at host address [xxxx] with IP address [yyyy] generated a 404 using the query string [/index.php?main_page=elsewhere].
The settings in my Configuration->Email Settings are
Code:
E-Mail Transport Method PHP
E-Mail Linefeeds LF
Use MIME HTML When Sending Emails true
What are your email settings?
Re: email body text not included in email
torvista, would you try this updated version of /includes/classes/class.emailFor404.php and let me know if it works?
Code:
<?php
class emailFor404 extends base {
/** constructor method !
*
* Attach observer class to the global $zco_notifier and watch for a single notifier event.
*/
function emailFor404() {
global $zco_notifier;
if (SEND_404_ERRORS_EMAIL_TO_STATUS == '1' and SEND_404_ERRORS_EMAILS_TO != '' and SEND_404_ERRORS_EMAILS_TO != '[email protected]') {
$zco_notifier->attach($this, array('NOTIFY_HEADER_END_PAGE_NOT_FOUND'));
}
}
/** Actual Method that does the desired activity
*
* Called by observed class when any of the notifiable events occur
*
* @param object $class
* @param string $eventID
*/
function update(&$class, $eventID, $paramsArray = array()) {
// BOF Send email to admin for 404 errors
$email_text = sprintf(EMAIL_PAGE_NOT_FOUND_CONTENT, $_SESSION['customers_host_address'], $_SESSION['customers_ip_address'], $_ENV['REQUEST_URI'])."\n\n";
$email_subject = EMAIL_PAGE_NOT_FOUND_SUBJECT;
$module = (SEND_404_ERRORS_EMAILS_ARCHIVE != '0') ? 'default' : 'no_archive';
$html_msg['EMAIL_SUBJECT'] = EMAIL_PAGE_NOT_FOUND_SUBJECT;
$html_msg['EMAIL_MESSAGE_HTML'] = str_replace('\n','',$email_text);
zen_mail('', SEND_404_ERRORS_EMAILS_TO, $email_subject, $email_text, STORE_NAME, EMAIL_FROM, $html_msg, $module);
// EOF Send email to admin for 404 errors
}
}
?>