User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 373,195 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,862 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1044 | Replies: 8 | Solved
Reply
Join Date: May 2008
Posts: 9
Reputation: oku is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
oku oku is offline Offline
Newbie Poster

PHP reminder E-mail - Cron job to run the script

  #1  
May 9th, 2008
Hello everyone,

Well i've just searched the forum to see if my question has been answered prioer to posting, but seem to find the answer.

Well basicly i've created a script to help me monitor and maintain the domain names my company owns (1000's)

I've virtually finished it but i am missing one bit - the auto email's reminding me when a domain will expire - I know you get the reminders from registrars but they only send to myself and others need to know this informaiton eg: Marketing, IT dept and i dont want them to have access to the domain contral panel at the registrar.

So i've been looking up possible ways to generate an automated email - but to no avail.

I have the following fields in my database:

domain_name, company_name, exp_date (Which is the expiry date in 0000-00-00format

So i was wondering if a cron job script can be run daily to check the domains that will expire in the next 7 days. For example if a domain had a exp_date as 2008-05-16 when the script is run on the 2008-05-09 an email will be sent to telling me such a domain is expiring soon.

If any 1 can point me in the right direction, i'd be very greatful

Many thanks

Dan
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2005
Posts: 606
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: PHP reminder E-mail - Cron job to run the script

  #2  
May 10th, 2008
Originally Posted by oku View Post
Hello everyone,

Well i've just searched the forum to see if my question has been answered prioer to posting, but seem to find the answer.

Well basicly i've created a script to help me monitor and maintain the domain names my company owns (1000's)

I've virtually finished it but i am missing one bit - the auto email's reminding me when a domain will expire - I know you get the reminders from registrars but they only send to myself and others need to know this informaiton eg: Marketing, IT dept and i dont want them to have access to the domain contral panel at the registrar.

So i've been looking up possible ways to generate an automated email - but to no avail.

I have the following fields in my database:

domain_name, company_name, exp_date (Which is the expiry date in 0000-00-00format

So i was wondering if a cron job script can be run daily to check the domains that will expire in the next 7 days. For example if a domain had a exp_date as 2008-05-16 when the script is run on the 2008-05-09 an email will be sent to telling me such a domain is expiring soon.

If any 1 can point me in the right direction, i'd be very greatful

Many thanks

Dan


Which do you have problems with, writing the PHP script or adding the script to cron?
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Join Date: May 2008
Posts: 9
Reputation: oku is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
oku oku is offline Offline
Newbie Poster

Re: PHP reminder E-mail - Cron job to run the script

  #3  
May 10th, 2008
Originally Posted by digital-ether View Post
Which do you have problems with, writing the PHP script or adding the script to cron?


The cron will be the easy part - its just structuring the script that i'm finding difficult
Reply With Quote  
Join Date: Sep 2005
Posts: 606
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: PHP reminder E-mail - Cron job to run the script

  #4  
May 10th, 2008
Originally Posted by oku View Post
The cron will be the easy part - its just structuring the script that i'm finding difficult


Really depends on how you're updating the database. If you're updating just for the case of sending out emails when the domains expire, then you can just delete the rows in the db when you send out an email..

Your query:
SELECT domain_name from domains_table where exp_date > NOW();

Iterate through each row, send email and remove row. Otherwise, you could add another column with the email send timeboolean. So your query would be something like:
SELECT domain_name from domains_table where exp_date > NOW() AND sent_email == FALSE;

Is that what you're trying to do?
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Join Date: May 2008
Posts: 9
Reputation: oku is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
oku oku is offline Offline
Newbie Poster

Re: PHP reminder E-mail - Cron job to run the script

  #5  
May 10th, 2008
Well - the query i would use would be very similar to what you posted -

where exp_date > NOW();

Once the domain has expired i dont intrend to delete the record from my database though.

The way i thought it would work would be:

When the domain is 1 week from expiring a query will be run checkin the dates in exp_date to see what domains are going to expire in 7 days

Then if there is a domain(s) about to expire in 7 days it will send an email reminder informing myself - and other members of staff that its goin to expire:

the email format will be something like this

Staff members name(s)

the following domain(s) will expire in 7 days

example.com
example.co.uk
example.net

Else no e-mail is sent until the cron job runs the next day
Or something similar - not to familiar with the mail function though in php
Last edited by oku : May 10th, 2008 at 10:38 am.
Reply With Quote  
Join Date: Sep 2005
Posts: 606
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: PHP reminder E-mail - Cron job to run the script

  #6  
May 10th, 2008
Originally Posted by oku View Post
Well - the query i would use would be very similar to what you posted -

where exp_date > NOW();

Once the domain has expired i dont intrend to delete the record from my database though.

The way i thought it would work would be:

When the domain is 1 week from expiring a query will be run checkin the dates in exp_date to see what domains are going to expire in 7 days

Then if there is a domain(s) about to expire in 7 days it will send an email reminder informing myself - and other members of staff that its goin to expire:

the email format will be something like this

Staff members name(s)

the following domain(s) will expire in 7 days

example.com
example.co.uk
example.net

Else no e-mail is sent until the cron job runs the next day
Or something similar - not to familiar with the mail function though in php


that should work...

PHP mail function.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Join Date: May 2008
Posts: 9
Reputation: oku is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
oku oku is offline Offline
Newbie Poster

Re: PHP reminder E-mail - Cron job to run the script

  #7  
May 11th, 2008
Been lookin at that php mail function today - was able to send a simple email using the examples that are provided

still figuring out how to email results from my query to be sent via email

ive structured a script below - it doesnt work but you can see what i am after

<?php

$host = "localhost"; 
$user = "user_name"; 
$pass = "password"; 
$db = "domains";


mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error());
mysql_select_db($db) or die("ERROR DB:".mysql_error()); 

$query="SELECT domain_name FROM domains WHERE exp_date > NOW()+7 ORDER BY domain_name ASC";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$domain_name=mysql_result($result,$i,"domain_name");
$company_name=mysql_result($result,$i,"company_name");
$simply_account=mysql_result($result,$i,"simply_account");
$notes=mysql_result($result,$i,"notes");
$exp_date=mysql_result($result,$i,"exp_date");



$to      = 'daniel.whiteside@googlemail.com';
$subject = 'Domain renewall reminder';
$message = '


The following domains will expire in 7 days

<BR><BR>

$domain_name - $company_name<BR>

<BR><BR>

Dont forget to renew!<BR><BR>

Domain Team


';
$headers = 'From: oku@sutsurikeru.net' . "\r\n" .
    'Reply-To: oku@sutsurikeru.net' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Not sure where i am going wrong
Reply With Quote  
Join Date: Sep 2005
Posts: 606
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: PHP reminder E-mail - Cron job to run the script

  #8  
May 18th, 2008
Originally Posted by oku View Post
Been lookin at that php mail function today - was able to send a simple email using the examples that are provided

still figuring out how to email results from my query to be sent via email

ive structured a script below - it doesnt work but you can see what i am after

<?php

$host = "localhost"; 
$user = "user_name"; 
$pass = "password"; 
$db = "domains";


mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error());
mysql_select_db($db) or die("ERROR DB:".mysql_error()); 

$query="SELECT domain_name FROM domains WHERE exp_date > NOW()+7 ORDER BY domain_name ASC";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$domain_name=mysql_result($result,$i,"domain_name");
$company_name=mysql_result($result,$i,"company_name");
$simply_account=mysql_result($result,$i,"simply_account");
$notes=mysql_result($result,$i,"notes");
$exp_date=mysql_result($result,$i,"exp_date");



$to      = 'daniel.whiteside@googlemail.com';
$subject = 'Domain renewall reminder';
$message = '


The following domains will expire in 7 days

<BR><BR>

$domain_name - $company_name<BR>

<BR><BR>

Dont forget to renew!<BR><BR>

Domain Team


';
$headers = 'From: oku@sutsurikeru.net' . "\r\n" .
    'Reply-To: oku@sutsurikeru.net' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Not sure where i am going wrong


try doing some dumps (var_dump or print_r) of your $message variable in the while loop to see if you're getting what you want.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Join Date: May 2008
Posts: 9
Reputation: oku is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
oku oku is offline Offline
Newbie Poster

Re: PHP reminder E-mail - Cron job to run the script

  #9  
May 18th, 2008
Hey digital-ether,

thanks for responding to my thread again.

I've been doing alot of reading and i've virtually clocked it

Now when the email sends - instead of just sending one email with the results of the query, it will send alot more

for example if the query returned 30 results it will send me 30 emails with each result of the query being in each email and i just want all results to appear one!

Here is the code im using - 90% there!

<?
mysql_connect("localhost","username","password"); 
mysql_select_db("database") or die( "Unable to select database"); 
 
 
$query="SELECT * FROM domains WHERE company_name = 'IWOOT' ORDER BY domain_name ASC";
$result=mysql_query($query);
 

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) 

{
 
  
$id=mysql_result($result,$i,"id");
$domain_name=mysql_result($result,$i,"domain_name");
$company_name=mysql_result($result,$i,"company_name");
$simply_account=mysql_result($result,$i,"simply_account");
$notes=mysql_result($result,$i,"notes");


$exp_date = mysql_result($result,$i,"exp_date");
$exp_date = date("d-m-Y", strtotime($exp_date) );


if($query == TRUE)
    {
           
      //send email
   
      $to = "daniel.whiteside@googlemail.com";
  
      $subject = "Expriy Notice";
   
      $from = "Admin";
   
  
      $msg .= "Hello Daniel,<BR><BR>";
  
      $msg .= "Domains for Iwoot...<BR><BR>";

      $msg .= "$domain_name - $exp_date <BR><BR>";  	

      $msg .= "Admin";
 
       
  
      $headers = "MIME-Version: 1.0" . "\r\n";
  
      $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
  
      $headers .= "From: Daniel Whiteside\r\nReply-To:oku@sutsurikeru.net" . "\r\n";
 
       
 
      $mailsend = mail("$to","$subject","$msg","$headers");
  
      echo $mailsend ? "Email was sent :-)." : " Email sending failed.";


$i++;
}

} 

?> 

Where am i going wrong?

Many thanks
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 10:04 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC