sending saved messages to different people via cron program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eldodgy
    New Member
    • Mar 2010
    • 4

    sending saved messages to different people via cron program

    I have set up a php file using a mysql querie which takes data from a media file from my database table.

    A series of different data rows gets called on a specific day and are sent out via a cron program sitting on our server.

    The problem is that the files are linking together . . . instead of going to the separate recipients they are grouping together in a string and being sent to everyone . . .

    How can I stop this from happening ! ! !
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    Well, you could show some code. Without code it could be anything.

    Comment

    • eldodgy
      New Member
      • Mar 2010
      • 4

      #3
      Code:
      <?php
      include("../includes/misc.php");
      
      $connection = mysql_connect($host,$user,$password)  
      				or die ("Couldn't connect to server.");
            $db = mysql_select_db($database, $connection)
      				or die ("Couldn't select database.");
      
      $result8 = mysql_query("SELECT directory.contact dir_contact, directory.contactemail dir_contactemail, A.event, A.name, A.contact, A.position, A.town, A.telephone, A.email, A.description, A.start, A.emailto, A.personaliseto, A.message, A.key1, A.notify, curdate()='date2', DATE_SUB(A.start, INTERVAL (A.notify) DAY) AS start1 FROM media A, directory WHERE (A.completed !='y') AND (DATE(DATE_SUB(A.start, INTERVAL (A.notify) DAY)) = DATE(curdate())) and A.ref = directory.ref");
      
      //$result8 = mysql_query("SELECT name, contact, position, town, event, telephone, email, description, start, emailto, personaliseto, message, key1, notify, curdate()='date2', DATE_SUB(start, INTERVAL (notify) DAY) AS start1 FROM media WHERE (completed !='y') AND (DATE(DATE_SUB(start, INTERVAL (notify) DAY)) = DATE(curdate()))"); 
      
      // (DATE(DATE_SUB(start, INTERVAL (notify) DAY)) = DATE(DATE_ADD(curdate(), INTERVAL 2 DAY)))");  
      
      while ($row8 = mysql_fetch_array($result8))                     
        		{
           	extract($row8); 
      			/*print $row8['start'] . " (" . $notify . ")";
      			print ("<br />");
      			print $row8['date2'];
      			print ("<br /><br />");*/
      			$to  = 'media@ygo.com.au' . ', '; // note the comma
      			$to .= 'rt@gbradio.com' . ', ';
      			$to .= $emailto . ', ';
      			$to .= $dir_contactemail;
      			$subject = "Entry Request - $name - $town - $event - $start - $key1";
      //			$messagebody = "To: ";
      //				if (empty($personaliseto))
      			{
      			$messagebody .= "To: ". $row8['personaliseto']."\n\n";
      			}
      //				else {$messagebody .= "Editor\n\n";}
      		
      //			ORIGINAL CONFIGURATION CHANGED TO ALLOW OTHER RECIPIENTS TO RECEIVE CONFIRMATION
      //			$to = $emailto;
      //			$subject = "Entry Request - $name - $town - $event - $start";
      //			$messagebody = "Dear ";
      //				if (empty($personaliseto)){
      //				$messagebody .= "".$row8['personaliseto']."\n\n";}
      //				else {$messagebody .= "Editor\n\n";}
      			
      			$messagebody .= "".$row8['message']."\n\n";
      			$messagebody .= "Event Name: " . $row8['event'] . "\n";
      			$messagebody .= "Event Start Date: " . $row8['start'] . "\n";
      			$messagebody .= "Event End Date: " . $row8['end'] . "\n\n";
      			$messagebody .= "Event Description: " . $row8['description'] . "\n\n";
      			
      			$messagebody .= "From: " . $row8['name'] . "\n";
      			$messagebody .= "Position: " . $row8['position'] . "\n";
      			$messagebody .= "Telephone: " . $row8['telephone'] . "\n\n";
      			$messagebody .= "Publishable Details\n";
      			$messagebody .= "Contact Name: " . $row8['contact'] . "\n";
      			$messagebody .= "Publishable Telephone Number: " . $row8['telephone'] . "\n";
      			$messagebody .= "Publishable Email Address: " . $row8['email'] . "\n\n";
      			$messagebody .= "Kind Regards\n" . $row8['name'] . "\n";
      			$messagebody .= "Brought to you by YGO Promotions\n\n";
      			$messagebody .= "________________________________\n\n\n";
      			//$messagebody .= "Start1 =" . $row8['start1'] . "\n";
      			//$messagebody .= "curdate =" . $row8['date2'] . "\n\n";
      			
      			
      			mail ($to, $subject, $messagebody, $headers);		
      			print $key1;
      			$query9 = "UPDATE media SET completed = 'y' WHERE key1 = '$key1'";
      			
      			$result9 = mysql_query($query9) or die ("Couldn't execute query1a.");
      		}
      
      ?>
      Last edited by Markus; Mar 4 '10, 01:58 PM. Reason: Added [code] tags

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4
        From what I can see (without 100% understanding your code) your $messagebody never resets but keeps growing. Fist line of code where it appears looks like this:

        Code:
        $messagebody .= "To: ". $row8['personaliseto']."\n\n";
        Basically you just extending string. You should find good place to reset your variables so they do not remember every iteration of your while loop.

        Hope this helps.

        Comment

        • eldodgy
          New Member
          • Mar 2010
          • 4

          #5
          Thank you for your input . . .

          I will look at what you are saying . . .

          Unfortunately as I did not write this particular code . . . coupled with my limited knowledge . . . it can be really frustrating

          Comment

          • zorgi
            Recognized Expert Contributor
            • Mar 2008
            • 431

            #6
            Just a small correction on my previous post. You did have place where you reset "$messagebo dy" but its commented out:

            Code:
            // $messagebody = "Dear ";

            Comment

            • eldodgy
              New Member
              • Mar 2010
              • 4

              #7
              Hi . . .

              Apparently the problem was a full stop and brackets as seen below:

              # {
              # $messagebody .= "To: ". $row8['personaliseto']."\n\n";
              # }


              #
              # $messagebody = "To: ". $row8['personaliseto']."\n\n";
              #

              This morning it worked fine . . .

              Thanks for your input

              Comment

              Working...