Automatic Email to selected persons for alerts

Reply

Join Date: Jun 2009
Posts: 268
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

Automatic Email to selected persons for alerts

 
0
  #1
Nov 15th, 2009
Hi, all this is my file expire_show.php
it shows expiry of those agreements which will expire with in 90 days from current date.
Users have to login to their accounts for viewing these expiry alerts.
but they require these alerts on their email.
1. how i can format these for email?
2 how I can send automatic email daily to selected persons?
  1. <?php
  2. $con = mysql_connect("localhost","root","root");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7.  
  8.  
  9. mysql_select_db("onm", $con);
  10.  
  11.  
  12. $result = mysql_query("SELECT * FROM lease_center WHERE (current_date() >= (LAPeriodEnd - INTERVAL 90 DAY)) AND (current_date() <= (LAPeriodEnd - INTERVAL 0 DAY)) ");
  13. while($row = mysql_fetch_array($result))
  14. {
  15. echo "<table cellpadding=2 cellspacing=2 width=100%>
  16. <tr>
  17.  
  18.  
  19. </tr>";
  20. echo "<tr>";
  21. echo "<th bgcolor=#FFCC00 width=250px>SiteId</th>";
  22. echo "<td bgcolor=#FEE9A9>" . $row['SiteId'] . "</td>";
  23. echo "</tr>";
  24. echo "<tr>";
  25.  
  26.  
  27.  
  28.  
  29. echo "<tr>";
  30. echo "<th bgcolor=#FFCC00>
  31. LAPeriodEnd</th>";
  32. echo "<td bgcolor=#FEE9A9>" .date("j-F-Y",strtotime($row['LAPeriodEnd'])). "</td>";
  33. echo "</tr>";
  34.  
  35. echo "<tr >";
  36. echo "<th bgcolor=#FF6600 height=10px>
  37. </th>";
  38. echo "<td bgcolor=#FF6600 height=10px></td>";
  39. echo "</tr>";
  40.  
  41.  
  42.  
  43. }
  44. echo "</table>";
  45.  
  46.  
  47. mysql_close($con);
  48.  
  49.  
  50.  
  51. ?>
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 177
Reputation: urtrivedi is an unknown quantity at this point 
Solved Threads: 32
urtrivedi urtrivedi is offline Offline
Junior Poster
 
0
  #2
Nov 15th, 2009
Copy above file to one another file.
Now you need this file to modify according to following algorithm.

  1. find users query
  2.  
  3. while (all users)
  4. {
  5. htmlmessage=""
  6.  
  7. while ( find all expired records for current user (as you are doing in your code for logged user only))
  8. {
  9.  
  10. create htmlmessage string intead of echoing output directly to browser.
  11. }
  12. mail('usermaiid',htmlmessage);
  13.  
  14.  
  15. }

You need to schedule above script to execute daily in midnight or any time you need using crontab on linux server and using schedule task on windows server.
Last edited by urtrivedi; Nov 15th, 2009 at 11:57 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 268
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training
 
0
  #3
Nov 16th, 2009
please do me favour.
Where i put my code.
i do not need login.
i have address like abc@xyz.com
then what i have to do?
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 177
Reputation: urtrivedi is an unknown quantity at this point 
Solved Threads: 32
urtrivedi urtrivedi is offline Offline
Junior Poster
 
0
  #4
Nov 16th, 2009
you can put your code along with other source file or any other location say cron folder. You may remove session login code from the begining of source file. because the new script will be executed by the system and not by the user. Mail function of php does not require email login.
Also You need to keep one column in exipry record table say "alert_mail_sent". after sending mail you need to set flag to yes.
If you dont do above things then user will get mail every day.

Modified code is as follows
  1.  
  2. find users query
  3.  
  4. while (all users)
  5. {
  6. htmlmessage=""
  7.  
  8. while ( find all expired records where mail is not sent for current user (as you are doing in your code for logged user only))
  9. {
  10.  
  11. create htmlmessage string intead of echoing output directly to browser.
  12. set mail sent flag for current user and current record to yes (mysql update)
  13. }
  14. if(htmlmessage!="")
  15. mail('usermaiid',htmlmessage);
  16.  
  17.  
  18. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 268
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training
 
0
  #5
Nov 16th, 2009
There is no need for user to login , he/she want this alerts on his/her email.
if address is abc@xyz.com
then how I will send the output of expire_show.php to above mention email address on daily basis.
User does not need to login...
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 268
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training
 
0
  #6
Nov 16th, 2009
I feel difficulty.
Please clear me.
If message is "you are welcome"
and I want to send this message daily to these addreses
abc@xyz.com
abc2@xyz.com
abc3@xyz.com
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 177
Reputation: urtrivedi is an unknown quantity at this point 
Solved Threads: 32
urtrivedi urtrivedi is offline Offline
Junior Poster
 
0
  #7
Nov 16th, 2009
I understand your requirement. Thats what I have mentioned in my algorithm.
Feature of above alorithm are as follows
1) Your scirpt will find all users with their email ids, (you must store email id of user in user table).
2) scipt will find all expire records for each user.
3) It will build email message for each user.
4) It will set alert_sent flag to YES to avoid repeatation of email message.( this column must be added in your expire record table)
5) It will use PHP mail function to send built message.
6) The above script will be scheduled on your web server to execute and send mail to the users everyday. mailing facity must be configured on Your web server.

7) user authendtication or login is not required

I hope you will get my point.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 268
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training
 
0
  #8
Nov 16th, 2009
I am new to email , please help me little in detail.
Thanks in advance...
I found following error
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 268
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training
 
0
  #9
Nov 16th, 2009
My mail setup is this and its still producing error.
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 177
Reputation: urtrivedi is an unknown quantity at this point 
Solved Threads: 32
urtrivedi urtrivedi is offline Offline
Junior Poster
 
0
  #10
Nov 16th, 2009
[mail function]
; For Win32 only.
SMTP = IP ADDRESS OF YOUR MAIL SERVER;
smtp_port = 25

If You write localhost you must configure your local server for mail operation.
Last edited by urtrivedi; Nov 16th, 2009 at 1:26 am.
Reply With Quote Quick reply to this message  
Reply

Tags
alerts, email

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1710 | Replies: 12
Thread Tools Search this Thread



Tag cloud for alerts, email
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC