Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Not quite sure whats wrong, i know IT IS SIMPLE i just not sure what..
Old 03-03-2008, 03:57 PM Not quite sure whats wrong, i know IT IS SIMPLE i just not sure what..
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Hello,

okay the script below, will be run as a cron job, and should send out emails for events which the user has set a "reminder" for but at the moment, it sends them out for all time periods. and not just the next down if that makes sense.

PHP Code:
<?php
include('../../includes/includes.php');
$result $db->query("SELECT * FROM event_reminders") or $db->query_error();
 while(
$row=$db->fetch_row($result))
 {
  
$event_res $db->query("SELECT * FROM events WHERE id='{$row['event_id']}'") or $db->query_error();
  
$event $db->fetch_row($event_res);
  
  
$user_res $db->query("SELECT * FROM users WHERE id='{$row['user_id']}'") or $db->query_error();
  
$user $db->fetch_row($user_res);
  
  
$headers "FROM: [CALM CMS CRON] <$from_email> \r\n";
  
$headers.= "Message-ID: <".time()."-$from_email>\r\n";
  
$headers.= "X-Mailer: PHP v".phpversion()." CALM CMS Cron Bot.\r\n";
  
$headers.= 'MIME-Version: 1.0'."\r\n";
  
$headers.= "Content-type: text/html; charset=iso-8859-1 \n\n";
  
$headers.= "\n\n";
  
  
$body "";
  
$body.= "Hello ".$user['fullname'].",<br />\r\n";
  
$body.= "You are recieving this email because you have set a reminder for ".$event['event'].".<br /><br />\r\n\r\n";
  
$body.= $event['event']." will be happening on ".date('l jS F y \a\t H:i'strtotime($event['date']))
    .
"<br /><br />\r\n\r\n";
  
$body.= "You may recieve future reminders for this event depending on your settings.<br />\r\n";
  
$body.= "To view, edit and delete this and other event reminders you have set, please visit: 
    <a href='http://calmcharity.org/user/'>calmcharity.org/user/</a><br /><br />\r\n\r\n"
;
  
$body.= "Hope to see you there!<br /><br />\r\n\n";
  
$body.= "Regards,<br />\r\n";
  
$body.= "CALM<br /><br />\r\n\r\n";
  
$body.= "<em>This email was automatically generated. If you do not want to recieve event reminders,<br />\r\n please           review your event reminder options in the user area, and do not subscribe to any more events.</em><br /> \n\r";
  
  
  
// If reminder set for month before event, and event email NOT sent.
  
if($row['month'] == && $row['month_sent'] == 0)
  {
   
// If 30days is MORE than current time minus the event date.
   
if(60*60*24*30 > (date('U') - strtotime($event['date'])))
   {
   
mail($user['email'], "[CALM] Reminder for: ".$event['event'], $body$headers);
   
$db->query("UPDATE event_reminders SET month_sent='1' WHERE id='{$row['id']}'");
   echo 
'Month email sent<br />';
   }
  }
  
  
// If reminder set for month before event, and event email NOT sent.
  
if($row['2weeks'] == && $row['2weeks_sent'] == 0)
  {
   
// If 14days is MORE than current time minus the event date.
   
if(60*60*24*14 > (date('U') - strtotime($event['date'])))
   {
   
mail($user['email'], "[CALM] Reminder for: ".$event['event'], $body$headers);
   
$db->query("UPDATE event_reminders SET 2weeks_sent='1' WHERE id='{$row['id']}'");
   echo 
'2 Week email sent<br />';
   }
  }
  
  
// If reminder set for month before event, and event email NOT sent.
  
if($row['week'] == && $row['week_sent'] == 0)
  {
   
// If 14days is MORE than current time minus the event date.
   
if(60*60*24*> (date('U') - strtotime($event['date'])))
   {
   
mail($user['email'], "[CALM] Reminder for: ".$event['event'], $body$headers);
   
$db->query("UPDATE event_reminders SET weeks_sent='1' WHERE id='{$row['id']}'");
   echo 
'Week email sent<br />';
   }
  }
  
  
// If reminder set for month before event, and event email NOT sent.
  
if($row['3days'] == && $row['3days_sent'] == 0)
  {
   
// If 14days is MORE than current time minus the event date.
   
if(60*60*24*> (date('U') - strtotime($event['date'])))
   {
   
mail($user['email'], "[CALM] Reminder for: ".$event['event'], $body$headers);
   
$db->query("UPDATE event_reminders SET 3days_sent='1' WHERE id='{$row['id']}'");
   echo 
'3 day email sent<br />';
   }
  }
  
 } 
// End while.
?>
The person who can tell me what im doing wrong will get some nice green rep.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 03-03-2008, 05:57 PM Re: Not quite sure whats wrong, i know IT IS SIMPLE i just not sure what..
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Fixed this now just had to swap this part:

PHP Code:
  if(60*60*24*30 > (date('U') - strtotime($event['date']))) 
</SPAN>

to this

PHP Code:
  if(60*60*24*30 > (strtotime($event['date']) - date('U'))) 
</SPAN>

and it seems to work
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Not quite sure whats wrong, i know IT IS SIMPLE i just not sure what..
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10208 seconds with 12 queries