'$thismonth';"; //$query4="select trim(nlemail),trim(nlidentifier) from newsletter where nlstatus='Active';"; //echo $query4; $query66=mysql_query($query4); mysql_close($mysqlconnect4); $users = array(); while ($result = mysql_fetch_array($query66)) { $users[] = $result;} // Create the replacements array $replacements = array(); foreach ($users as $user) { $replacements[$user["nlemail"]] = array ("{unsubscribeidentifier}" => $user["nlidentifier"]); } error_reporting(0); // Create the mail transport configuration $transport = Swift_SmtpTransport::newInstance('mail.giveback.co.za', 587) ->setUsername('noreply@giveback.co.za') ->setPassword('Sumatra01'); // Create an instance of the plugin and register it $plugin = new Swift_Plugins_DecoratorPlugin($replacements); //Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); $mailer->registerPlugin($plugin); /*Register anti flood plugin The AntiFlood plugin is designed to help lessen the load on the HTTP server and the SMTP server. It can also be used to send out very large batches of emails when the SMTP server has restrictions in place to limit the number of emails sent in one go. */ $mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(50, 30)); //Additional stuff $nowdate=date("YmdHis"); $yoursubject="Give Back Newsletter, ".date('jS \of F Y'); $subjectToSend=$yoursubject; //Create Message //Initialise $mymailmessage .=' Hi there!

Greetings on this '.date(l).' from everyone at Give Back.

You have received this because your email address has been listed next to a charity organisation on Give Back.
Find below a few of the entries on our Message Board.
Clicking on the links will take you to the Give Back website where you can find more details about the notice.

'; $noticetypetags=array("I am looking for a charity...", "A Charity is looking for...", "New Charity"); $searchresult="NotFound"; foreach ($noticetypetags as &$value) { $bgtablecolour="grey"; $query="select noticenum,noticetitle,date,requesttype,subname,sublocation,noticetype from noticeboard where (noticetype='".$value."') and (requesttype='Notice' or requesttype='Charity') and (unix_timestamp()-unix_timestamp(date)<15638400) order by date desc limit 5"; $mysqlconnect=mysql_connect('localhost','giveback_admin','admin') or die ('Error. Please notify Give Back.'); mysql_select_db('giveback_charityorgs'); $result=mysql_query($query); $emailnoticecounter=0; $tablelineemail.= 'Section: ' . $value. ''; $tablelineemail.=" "; while ($line = mysql_fetch_array($result, MYSQL_NUM)) { $emailnoticecounter++; $searchresult="Found"; $vcscharitydate=$line[2]; $vcscharitydetails=$line[1]; $vcscharitynum=$line[0]; $vcsrequesttype=$line[3]; $vcsrequestnum=$line[4]; $vcsrequestlocation=$line[5]; $vcsnoticetype=$line[6]; $vcscharitydate2=date('d M',strtotime($vcscharitydate))." '".date('y',strtotime($vcscharitydate)); if ($vcsnoticetype != 'New Charity') {$linktogoto='http://www.giveback.co.za/noticedetail.php?noticenum='.$vcscharitynum;} if ($vcsnoticetype == 'New Charity') {$linktogoto='http://www.giveback.co.za/charitydetail.php?charitynum='.$vcsrequestnum;} if ($bgtablecolor=="white") {$tablelineemail.='';$bgtablecolor="grey";} else {$tablelineemail.='';$bgtablecolor="white";} $tablelineemail.= '
'; } if ($vcsnoticetype == 'New Charity'){ $tablelineemail.= ''; $tablelineemail.= ''. $vcsrequestlocation.''; } } mysql_close($mysqlconnect); if ($searchresult=="Found") {$tablelineemail.= "
'.$emailnoticecounter.'. '. $vcscharitydetails . ''; if ($vcsnoticetype != 'New Charity') { $tablelineemail.= '
'. $vcsrequestnum . ','; $tablelineemail.= ''. $vcsrequestlocation.'
"; } $tablelineemail.= "
"; } //End initialise Create Message $firsttext= 'Till next time,
Thanks for giving back!

Note: This mail is from an unattended mailbox. Please do not reply to it.
To unsubcribe, click on: Unsubscribe from the Give Back Newsletter
Please go to Comment on Give Back and let us know if you have received this mail in error.
And finally, please find Give Back on Facebook. Remember to Like to raise awareness!
'; $myemailfilename="/home/giveback/public_html/newsletteremailfile.txt"; $handlefile = fopen($myemailfilename, "a"); fwrite($handlefile,"Now I am about to write something on ".date("Y-m-d H:i:s")."\n"); fwrite($handlefile,"Start dumping output...".date("Y-m-d H:i:s")."\n"); $message = Swift_Message::newInstance($subjectToSend); $message->setFrom(array('donotreply@giveback.co.za' => 'Give Back')); $message->setBody($mymailmessage.$tablelineemail.$firsttext."{unsubscribeidentifier}".$secondtext,'text/html'); //$message->setBody($mymailmessage.$tablelineemail.$firstext.$secondtext,'text/html'); /* $message->setBody( "Hello {unsubscribeidentifier}, we have reset your password to {password}\n" . "Please log in and change it at your earliest convenience." ) ; */ // Send the email foreach($users as $user) { $message->setTo($user["nlemail"]); //if ($user["nlemail"]=='shane.pillay@gmail.com') {$mailer->send($message);} $mailer->send($message); fwrite($handlefile,$user["nlemail"].",".$user["nlidentifier"]."\n"); $usermail=$user["nlemail"]; $mysqlconnect412=mysql_connect('localhost','giveback_admin','admin') or die ('Error. Please notify Give Back.'); mysql_select_db('giveback_charityorgs'); $query412="update newsletter set nldatecheck='$thismonth' where nlemail='$usermail';"; $query6612=mysql_query($query412); mysql_close($mysqlconnect412); } fwrite($handlefile,"This is the end...".date("Y-m-d H:i:s")."\n"); fclose($handlefile); ?>