Page 1 of 4 123 ... LastLast
Results 1 to 10 of 33

Thread: Send Me An Email Of Birthdays

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Send Me An Email Of Birthdays

    I'm not sure how this would work automatically but I was wondering how I can send myself an email say 2 weeks before a member in my database is about to have a birthday? I'm assuming the query would need to be running constantly so would it be possible?

  2. #2
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Implausible, or at least, not a good idea.

    you cant have one script running forever. the server would end up crashing.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  3. #3
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No I'll set up the script and then run it as a cron job, that should work I think...

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Cron would work (or scheduled tasks in a Windows environment), although it is not recommended (due to it being a resource hog). However, if you would like something like this, the script could be something similar to this:

    bday.php
    PHP Code:
    <?php
    $to 
    "me@mydomain.com"//your email address
    $subject "Member's birthdays"//subject of email

    include('dbconnect.php');
    $year date('Y');
    $month date('m');

    $results mysql_query("SELECT * FROM `table` WHERE `birthday` LIKE '$year-$month%'");

    if (
    mysql_num_rows($results) < 1) {
    die(
    'There are no members with birthdays this month');
    }

    else {

      while (
    $qry mysql_fetch_array($results)) {
          if (
    strtotime($qry['birthday']) <= (time() + 86400*14)) {
             
    $bdays[] = Array($qry['Name'] => $qry['birthday']);
          }
      }

    $message 'Below is a list of the members and their birthdays that are coming up in the next couple of weeks. \r\n';

    $message .= 'The birthdays are as follows: \r\n';
    $message .= '-----------------------------------------\r\n\r\n';

    foreach (
    $bdays as $name => $bdate) {
       
    $message .= 'Name (Birthday): '.$name.' ('.$bdate.') \r\n';
    }

    $from "From: PHP Script <noreply@mydomain.com";

    mail($to$subject$message$from);
    }
    ?>
    Note: not tested, but should work with little modification.

    Hope this helps.
    Last edited by thetestingsite; 03-14-2007 at 11:38 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I had a quick question when I am doing includes, is there any difference i doint them like this include
    PHP Code:
    include 'dbconnect.php'
    or like this
    PHP Code:
    include('dbconnect.php'); 

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I don't think that it matters, I've just always done include('somefile.txt'); as compared to your way above. I believe they all work the same, but then again I'm not 100&#37; sure. You may want to look at the php.net website and look for this.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It said there was an error on line 23, I change the names to be what's in my database columns yea?
    PHP Code:
             $bdays[] = $qry['FirstName'] => $qry['DateOfBirth']; 

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try this:

    Code:
    $bdays[] = Array($qry['FirstName'] => $qry['DateOfBirth']);
    Then in the code above the while statement, get rid of this:

    Code:
    $bdays = Array();
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Cool, well it ran and the result was "There are no members with birthdays this month", but there are about 1000 members so I find that hard to believe... But also on my other birthday post in this forum, no matter what month I change it too it tells me there aren't any bdays... Any ideas?

  10. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    What's the link to the other post? Also, I just made that script when I posted it, so it is not tested. Just a quick question, how is the birthdate field formed? (Datetime, text, timestamp, etc?). This could be why you are not getting results because it is searching for any birthdays like this:

    2007-03*
    2007 is the year, 03 is the month (for March), and * is the wildcard
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •