craigtolputt Posted March 5, 2009 Share Posted March 5, 2009 Hi Guys, I have a php script at the moment which i had developed for me that when the cron job calls the php file it checks the table in the database andif any of the records are set to new or updated it saves them off as a csv file zips it up and adds a password and then sends the zipped up file to an email adress.... So my question is can i modify this script slighty so that the cron job calls the php script, which checks the table for new entries and then simply sends all the new entries in an email as a newsletter to all the email address's in another table? hope this is clear enough to someone with better php knowledge. cheers Link to comment https://forums.phpfreaks.com/topic/148071-checking-the-database-for-new-news-items-and-sending-them-out-as-a-newsletter/ Share on other sites More sharing options...
craigtolputt Posted March 5, 2009 Author Share Posted March 5, 2009 This is what i have at the moment to check the database table for new entries and then create the CSV file <?php include "connect.php"; $tableName = "DNAreg"; $_file = 'nData.csv'; $_fp = @fopen($_file,'w'); $result=mysql_query("select username,Identifier,Salutation,FirstName,LastName,Company,Address1,Address2,City,County,Postcode,PhoneNumber,Mobile,StartDate,Location,Status,isUpdate FROM $tableName where IsNew=1",$con); $num_rows = mysql_num_rows($result); if($num_rows>0) { while ($row = mysql_fetch_row($result)) { $aIdentifier = str_replace(","," ",$row[1]); $aSalutation = str_replace(","," ",$row[2]); $aFirstName = str_replace(","," ",$row[3]); $aLastName = str_replace(","," ",$row[4]); $aCompany = str_replace(","," ",$row[5]); $aAddress1 = str_replace(","," ",$row[6]); $aAddress2 = str_replace(","," ",$row[7]); $aCity = str_replace(","," ",$row[8]); $aCounty = str_replace(","," ",$row[9]); $aPostcode = str_replace(","," ",$row[10]); $aPhoneNumber = str_replace(","," ",$row[11]); $aMobile = str_replace(","," ",$row[12]); $aStartDate = str_replace(","," ",$row[13]); $aLocation = str_replace(","," ",$row[14]); $aStatus = str_replace(","," ",$row[15]); $isUpdate =str_replace(","," ",$row[16]); $_csv_data = ''; if($isUpdate==1) { $isUpdate=0; } else { $isUpdate=1; } $_csv_data=$aIdentifier.','.$aSalutation.','.$aFirstName.','.$aLastName.','.$aCompany.','.$aAddress1.','.$aAddress2.','.$aCity.','.$aCounty.','.$aPostcode.','.$aPhoneNumber.','.$aMobile.','; //$_csv_data.=$aStartDate.','.$aProduct.','.$aLocation.','.$aStatus.','.$aInstComp.','.$aInstEng.','.$aIdentifier. "\n"; $_csv_data.=$aStartDate.','.$aLocation.','.$aStatus.','.$isUpdate. "\n"; @fwrite($_fp, $_csv_data); mysql_query("UPDATE $tableName SET IsNew=0 WHERE Identifier = '$aIdentifier' ",$con); } @fclose($_fp); include "ZipPwd.php"; include "sendZipFileAsEmail.php"; } ?> Link to comment https://forums.phpfreaks.com/topic/148071-checking-the-database-for-new-news-items-and-sending-them-out-as-a-newsletter/#findComment-777212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.