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?

<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db("onm", $con);


$result = mysql_query("SELECT * FROM lease_center WHERE (current_date() >= (LAPeriodEnd - INTERVAL 90 DAY)) AND (current_date() <= (LAPeriodEnd - INTERVAL 0 DAY)) ");
while($row = mysql_fetch_array($result))
  {
  echo "<table cellpadding=2 cellspacing=2 width=100%>
<tr>


</tr>";
  echo "<tr>";
  echo "<th bgcolor=#FFCC00  width=250px>SiteId</th>";
  echo "<td bgcolor=#FEE9A9>" . $row['SiteId'] . "</td>";
    echo "</tr>";
  echo "<tr>";
						

	
	
	echo "<tr>";
  echo "<th bgcolor=#FFCC00>
  LAPeriodEnd</th>";
  echo "<td bgcolor=#FEE9A9>" .date("j-F-Y",strtotime($row['LAPeriodEnd'])). "</td>";
    echo "</tr>";
	
	echo "<tr >";
  echo "<th bgcolor=#FF6600 height=10px>
</th>";
  echo "<td bgcolor=#FF6600 height=10px></td>";
    echo "</tr>";
	
	
	
  }
echo "</table>";


mysql_close($con);



?>

Copy above file to one another file.
Now you need this file to modify according to following algorithm.

find users query

while (all users)
{
	htmlmessage=""

	while ( find all expired records for current user (as you are doing in your code for logged user only))
	{

		   create htmlmessage string intead of echoing output directly to browser.
	}
	mail('usermaiid',htmlmessage);
   
  
}

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.

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?

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

find users query

	while (all users)
	{
		htmlmessage=""

		while ( find all expired records where mail is not sent for current user (as you are doing in your code for logged user only))
		{

		   create htmlmessage string intead of echoing output directly to browser.
		   set mail sent flag for current user and current record to yes (mysql update)
		}
                if(htmlmessage!="")
			mail('usermaiid',htmlmessage);
   
  
	}

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...

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.

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()

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

[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.

I have change and write 20.106.50 but its not working..

"20.106.50" This is not a valid ip address . find actual ip address. save php ini file after modification and then restart apache services

Ok, I will try

NEED TO CREATE AN AUTOMATIC MAILER THAT GOES TO EVERY SUBSCRIBED MEMBERS ON EVERY MONDAY AUTOMATICALLY. HAVE CREATED THE MAILER JUST NEED SOME CODE HOW TO SEND THEM AUTOMATICALLY. HAVE HEARD ABOUT CRON JOBS BUT NOT SURE HOW TO IMPLEMENT. CAN ANYBODY HELP...!!!!!

You can use crontab as given in following link
I am assuming your server having linux

1) make php script ready for sending mail
2) configure job using crontab command crontab -e
3) add your script entry with time to execute.

00 01 * * 1 wget -q -O /dev/null http://www.domoinname.com/cronfolder/mailfile.php?para1=value1

Above command means your script (mailfile.php) will run at 1 am in morning on every monday

http://www.cs.sjsu.edu/faculty/froomin/Handouts/Crontab.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.