Hi, when I develope an email module, i got the following problems:

  1. when I send email manually, yahoo email account couldn't receive my email. but gmail.com and others can get email without problem.

  2. How to let the system send an automate email based on the date (like birthday). Every day will send an system automate email to those users which have relative date.

Thank you for your reply!

    Originally posted by sunnyside
    How to let the system send an automate email based on the date (like birthday). Every day will send an system automate email to those users which have relative date.

    i assume you are storing all the birthday data in a database. pull all the data based on the current date. something like:

    SELECT birthday FROM table WHERE MONTH(birthday) = MONTH(CURDATE()) AND DAYOFMONTH(birthday) = DAYOFMONTH(CURDATE())
    

    loop thru the results and send an email using [man]mail[/man]

      Originally posted by devinemke
      i assume you are storing all the birthday data in a database. pull all the data based on the current date. something like:

      SELECT birthday FROM table WHERE MONTH(birthday) = MONTH(CURDATE()) AND DAYOFMONTH(birthday) = DAYOFMONTH(CURDATE())
      

      loop thru the results and send an email using [man]mail[/man] [/B]

      Hi, I think I know how to use MySql query to get the date. But I just kind of confused where I should call this recall.php which contains mail function.

        a very simplified example (just guessing here at your data structure):

        // connect to db first
        
        $result = mysql_query('SELECT *, YEAR(birthday) AS year FROM table WHERE MONTH(birthday) = MONTH(CURDATE()) AND DAYOFMONTH(birthday) = DAYOFMONTH(CURDATE())');
        
        $subject = 'Happy Birthday!';
        $from = 'from: Sunnyside <sunnyside@sunnyside.com>';
        $year = date('Y');
        
        while ($row = mysql_fetch_assoc($result))
        {
        	$age = $year - $row['year'];
        	$message = 'Dear ' . $row['name'] . ',' . "\n\n" . 'You were born on ' . $row['birthday'] . ' which makes you ' . $age . ' years old today.';
        	$to = $row['name'] . '<' . $row['email'] . '>';
        
        $mail = mail($to, $subject, $message, $from);
        if ($mail) {echo 'mail send OK<br>';} else {echo 'mail send FAIL<br>';}
        }
        

          Thank you for both of your help! But here's my another question:

          If I had done db query and email function, also it worked well. How and where do I call this php file (currently name it as date_recall.php) If I called this php twice a day, does it mean I'm gonna send reminder email twice?

          dewen, you said

          setup a cron with crontab -e # call the script throu http everyday 7am ...

          Can you tell me where I should put this script in Windows & Linux?

          Thank you again!

            for windows, I'm not sure. there are something like job or task in admin serivce to do it. On linux, crontab is a command, you can read the manual on to use it. The idea is for each user to setup a scheduled work to exec some script, command, etc.

              I assume this is a website, not just a email script to email your friends on there bday.

              Create this table.


              create table emails_sent (id PRIMARY KEY AUTO_INCREMENT, timestamp int(12), userid int(12), key (userid), key (timestamp));

              (user id or user name)


              Everytime a email is sent for the bday add to this table a row containing the user name/id and the time added.

              Now add a check to make sure you only email each user once.

              Also every time its run delete rows where the timestamp is greater then a day old.

                Write a Reply...