Question : How to send email on mysql insert error?

Hi Experts,

Background:
I have a script that runs on a cron job every 5 minutes that pulls in a csv file from a remote location and inserts each line into a mysql database. It all works fine but what I need and cannot work out how to do, is fire an email off to admin if there is an error on import. Usually it is due to a malformed csv file but it might be several hours before I notice that the imports have stopped and are starting to jam up.

Is there a way that on such error an email can be sent, perhaps with the filename in so I can be notified without having to check every 5 minutes.
Thanks in advance.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
$csv_directory = opendir("admin/csvfiles/");
$number_of_files = 0;
While($filename = readdir($csv_directory)) {

	If ($filename != ".." && $filename != "." && $filename != "_vti_cnf") {
		$local_file  = "admin/csvfiles/" . $filename;
		$fp = fopen ("$local_file","r");
		while ($data = fgetcsv ($fp, 1000, ",")) {
			$import="INSERT INTO deliveries VALUES ('', '$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]','$data[12]','$data[13]','$data[14]','$data[15]','$data[16]','$data[17]','$data[18]','$data[19]','$data[20]','$data[21]','$data[22]','$data[23]')";
			mysql_query($import) or die(mysql_error());
		}
		unlink($local_file);
		fclose ($fp);
		$number_of_files++; 	
	}
}

Answer : How to send email on mysql insert error?

I would suggest clamav.
Here is a tutorial for ubuntu : http://www.ubuntugeek.com/howto-install-clam-antivirus-with-gtk-frontend-gui.html
Random Solutions  
 
programming4us programming4us