This topic is locked
[SOLVED]

Please help to send a conditional email

8/29/2021 2:18:17 PM
PHPRunner General questions
M
muammer author

Hello,
1- I want to send some of my record contents in the table by e-mail to the e-mail addresses in the same table, depending on the conditions such as expired, 1 day past or 1 day before the due date in relation to the date field in my job tracking table. and this mail should go once a day as long as the conditions are met.
2- If the first option is very complicated and complicated, it will be sufficient to issue a notification or a pop-up window warning on the screen if the conditions are met as I explained in the 1st item above for the jobs they follow.

  • I haven't seen any examples in the forum and phprunner guide of sending a specific conditional mailing or notification.
  • I think it is important in which event log this sample code will be executed.
  • I would like to thank those who will share a sample code or a redirect to send an e-mail to the records subject to the date condition.
    *At the same time, the conditions must be consecutive, and whichever condition occurs, the mail must be sent according to the provided condition.

*I have shared a sample code below. I used this code in listpage: after record processed event but it didn't work.

if($data["date"]>now())
{
$email=$data["Email"];
$from="info@kenarhukuk.com";
$msg="You have an expired job follow-up.";
$subject="info";
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from,));

if(!$ret["mailed"])
echo $ret["message"];

};
HJB 8/29/2021

MassMailer template - send email newsletters and automatic daily/weekly emails

Though it is of course possible to achieve of what you are looking for by manual coding,
I would recommend you to run a $50 investment into the "MassMailer" template, simply
because you have a much better overview of what is going on.

You own (among other features) automation by CRON jobs (if supported by your server
configuration), you can even add attachments under password protection "... on the fly ...",
in shortage, it can save you a lot of time on manual coding hours and testing.

As per latest info from the developers, numerous TEMPLATES like e.g. this one have not yet
been upgraded to v10.6 yet as this version is still relatively young, and so, I recommend to
buy the "massmailer" template once the upgrade to v10.6 has been fully done.

P.S. Once the "MassMailer" is finally in your hands, you can find the MySQL query codes for
your mentioned conditional date requirements to feed the "MassMailer" with same under:

DATE/TIME HANDLING IN WEB APPLICATIONS

M
muammer author 8/29/2021

Mr. HJB
Thank you very much for your suggestions. But I don't know if it is possible to send the registration information in the fields of the tables or pages I want in my application with the MassMailler template. I couldn't see the live demo on the site where the templates are. I couldn't find any detailed information about his abilities.
In Phprunner 10.6, the notification API was also going to come, I think the work is in progress.
But what I want is that certain records from the tables that I want specific to myself go when certain conditions are met, and I would prefer to do this if possible. However, if there is an example application or way, I would like to use it in my own projects.
There have been many questions on the forum to send a certain conditional email on this subject, but there is no satisfactory answer or example. I didn't see it in the phprunner manual either.
I would like to thank those who will produce a solution or show the way. I'll be waiting for answers.

admin 8/29/2021

Sending a conditional email is easy, you check some condition and if it is met, you send the email. There is nothing PHPRunner specific in this task, just basic PHP programming.

If you need an basic example check this post for instance:
https://asprunner.com/forums/topic/23668-send-email-conditional

MassMailer template will also do the job, and it can be useful if you need to send those emails automatically, without having users to go to your website. Check this blog post:
https://xlinesoft.com/blog/2016/01/29/massmailer-template-use-case/

HJB 8/29/2021

Yours "But what I want is that certain records from the tables that I want specific to myself go
when certain conditions are met, and I would prefer to do this if possible.
" refers ...

Let me try to explain: As pointed by @admin, the manual coding inside PHPRunner can easily launch
an e-mail once some defined (by manual code) conditions are met. In other words, such coding is mainly
used for things like "... send an e-mail ..." of NEW entered data (to admin, to user, to BCC recipients etc pp).
Or other example, once a form set is going to be completed under "step-by-step" form filling method, e.g.
in shipping business you have BOOKING DATE, ARRIVAL AT PORT TERMINAL, LOADED ABOARD DATE,
DEPARTURE DATE OF SHIPPING VESSEL, ARRIVAL DATE AT CLIENT'S PORT LOCATION and even more.
Each time, the form is filled with dates as mentioned above, an e--mail is automatically launched to inform
the CLIENT and maybe others too. Here the manual coding as pointed out by @admin can do very fine.

On the other hand, if you want to own e-mailed reports to only YOURSELF as you said, manual coding can
become very tedious and so, with "MassMailer's" user interface, it is much easier especially then, if you have
tasted how fine automated e-mail despatch in even intervals (every 5 minutes, every 8 hours, once a day, once
a week, or monthly for example) and you want to automate more that the just needed tasks.

Simply speaking, the manual coding method via PHPRunner is forming a part of your overall project code while
the "Massmailer" is likely acting like a Co-Pilote (or say, WING COMMANDER) to your web application and is
NOT forming a part of your project code at all (except when pulling needed data from same by MySQL queries).

Of course, you can reach any location with a bicycle, training your leg muscles and more, but if you can buy a
"Maybach" like luxury vehicle at $50, namely "MassMailer", your legs remain untrained, yet you can use the time
in the vehicle (a car) to make phone calls or design a new business plan for example, and best, you arrive at your
wished location in faster time and in a totally relaxed mood.

M
muammer author 8/29/2021

Dear admin and HJB,

Thank you very much for your directions, I created a solution with your suggestion, I will share my scenario with the aim of helping friends in the forum.
1- In my project, I have a table with job tracking. In this table, I have id, registration date, status, subject, work to be done, deadline, email tracking fields, respectively.
2a- I created the create view table so that my table is not visible to users
2b- in this table I filtered only the to-do tasks in the status column (because I only want to-do tasks to go to email)
2c- Later, I wrote the conditional mail sending codes according to the date, and I wrote this event to the (listpage: before record procced) event.
2d- I created 3 conditions by date

  • My first condition is that the job expired email is sent for those whose job has expired. (due date of work < today date)
    *my second condition is if job deadline equals today's date (job deadline = today's date)
  • My third condition is that if tomorrow's day is the last date of the job and the remainder is 1, that is, if the job is equal to the deadline tomorrow, I tried to provide the condition, but I got an error here, I need help with this. (tomorrow date - work deadline =1)
    Below is the code I used in the listpage:before record procced event. but my third condition is not working i need help here.
    ////////////////////////
    if($data["Son_Tarih"]<date("Y-m-d", time())){


$email=$data["Email_Takip"];
$from="info@kenarhukuk.com";
$msg="";
$subject="Tarafınıza Atanan"." ".$data["Dosya_id"]." "."Nolu"." ".$data["Muvekkil"]." "."dosyasında,"." "."SÜRE KAÇIRILDI.";

$msg.= "Sayın:"."<b>".$data["Sorumlu"]."</b>"."<br/>\n";
$msg.= "Takibinizde olan"." "."<b>".$data["Dosya_id"]."</b>"." "."Nolu"." "."<b>".$data["Muvekkil"]."</b>"." "."dosyasında ki iş takip kaydı,"." "."<b>".$data["Atayan"]."</b>"." "."tarafından güncellenmiştir. "."<br/>\n";
$msg.="Yapılacak olan İş: "."<b>".$data["Yapilacak_is"]."</b>"." "."olup,"."<br/>\n";
$msg.= "İşin Son Tarihi: "."<b>".$data["Son_Tarih"]."</b>"." "."dir."."<br/>\n";
$msg.=""."Güncellenen iş takibini açmak için tıklayın >>>"." "."www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com/portaltest/is_takibi_ekrani_view.php?editid1=".$data["id"]."<br/>\n'>https://www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com/portaltest/is_takibi_ekrani_view.php?editid1=".$data["id"]."<br/>\n"."
";
$msg.="İyi Çalışmalar Dileriz. www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'htmlbody' => $msg, 'from'=>$from));
if(!$ret["Mail Gönderildi"])
echo $ret["Mail başarılı şekilde gönderildi"];

}
////////////////////////////////////////////////////////////////////////
if($data["Son_Tarih"]==date("Y-m-d", time())){

$email=$data["Email_Takip"];
$from="info@kenarhukuk.com";
$msg="";
$subject="Tarafınıza Atanan"." ".$data["Dosya_id"]." "."Nolu"." ".$data["Muvekkil"]." "."dosyasında,"." "."SON GÜN.";

$msg.= "Sayın:"."<b>".$data["Sorumlu"]."</b>"."<br/>\n";
$msg.= "Takibinizde olan"." "."<b>".$data["Dosya_id"]."</b>"." "."Nolu"." "."<b>".$data["Muvekkil"]."</b>"." "."dosyasında ki iş takip kaydı,"." "."<b>".$data["Atayan"]."</b>"." "."tarafından güncellenmiştir. "."<br/>\n";
$msg.="Yapılacak olan İş: "."<b>".$data["Yapilacak_is"]."</b>"." "."olup,"."<br/>\n";
$msg.= "İşin Son Tarihi: "."<b>".$data["Son_Tarih"]."</b>"." "."dir."."<br/>\n";
$msg.=""."Güncellenen iş takibini açmak için tıklayın >>>"." "."www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com/portaltest/is_takibi_ekrani_view.php?editid1=".$data["id"]."<br/>\n'>https://www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com/portaltest/is_takibi_ekrani_view.php?editid1=".$data["id"]."<br/>\n"."
";
$msg.="İyi Çalışmalar Dileriz. www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'htmlbody' => $msg, 'from'=>$from));
if(!$ret["Mail Gönderildi"])
echo $ret["Mail başarılı şekilde gönderildi"];

}

////////////////////////////////////////////////////////////////////

if(date_diff(date("Y-m-d", time()+86400),$data["Son_Tarih"])==1){

$email=$data["Email_Takip"];
$from="info@kenarhukuk.com";
$msg="";
$subject="Tarafınıza Atanan"." ".$data["Dosya_id"]." "."Nolu"." ".$data["Muvekkil"]." "."dosyasında,"." "."YARIN SON GÜN.";

$msg.= "Sayın:"."<b>".$data["Sorumlu"]."</b>"."<br/>\n";
$msg.= "Takibinizde olan"." "."<b>".$data["Dosya_id"]."</b>"." "."Nolu"." "."<b>".$data["Muvekkil"]."</b>"." "."dosyasında ki iş takip kaydı,"." "."<b>".$data["Atayan"]."</b>"." "."tarafından güncellenmiştir. "."<br/>\n";
$msg.="Yapılacak olan İş: "."<b>".$data["Yapilacak_is"]."</b>"." "."olup,"."<br/>\n";
$msg.= "İşin Son Tarihi: "."<b>".$data["Son_Tarih"]."</b>"." "."dir."."<br/>\n";
$msg.=""."Güncellenen iş takibini açmak için tıklayın >>>"." "."www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com/portaltest/is_takibi_ekrani_view.php?editid1=".$data["id"]."<br/>\n'>https://www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com/portaltest/is_takibi_ekrani_view.php?editid1=".$data["id"]."<br/>\n"."
";
$msg.="İyi Çalışmalar Dileriz. www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com'>www.kenarhukuk.com";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'htmlbody' => $msg, 'from'=>$from));
if(!$ret["Mail Gönderildi"])
echo $ret["Mail başarılı şekilde gönderildi"];

}

return true;


3. If all the conditions are met, now we are setting the link of our list page to the crone jobs of our server to ensure that the mail is sent at the time intervals we want, and our mails will automatically send mail when the desired conditions are met even when our web page is closed.
HJB 8/30/2021

Comparison Operators

... please study a.m. URL content and make GOOD use respectively correct choose of the right
comparison operator.

Example (your own code):

if(date_diff(date("Y-m-d", time()+86400),$data["Son_Tarih"])==1){

practically means this: You are ADDING 86400 seconds to a pulled datetime formatted field while
your comparison operator instructs to only include data which returns EXACTLY (== comparison
operator) the integer 1, in other words, the usage of "==" is only pointing to a certain datetime.

However you do NOT want to include an exact match datetime match, but a TIME range, so, you
need to apply the "<=" comparison operator rather than the "==" to properly define the TIME RANGE.

Simply speaking, you want to INCLUDE all tomorrow's datetime issues which are equal to 1 and lower.

P.S. Any significant platform with users to access data is already a challenge in regard to workloads of
users to keep the data up-to-date. Now, adding roboted mails to users by e-mail to them point to data

entries needs to be seen before the fact that any e-mail box these days is flooded with advertising and
private as well as business mails too. So, on the long run (months, years) a roboted mail system, once
not prudently managed by prudent time interval sin regard to despatch of mails owns the risk to simply
exhaust the users by means of additional work load. From that very point of view I recommend to ponder
over whether or not some roboted mail content can be converted into inside table information by means
of "conditional formatting" as per URL below. In other words, users are guided e.g. guided what still needs
to be done by means of RED COLOURED data entries.

Navigation: Using PHPRunner > Page Designer > "View as" settings Conditional formatting

M
muammer author 8/30/2021

Mr. HJB
I will take your advice and suggestions into consideration. Thank you very much for your help. Conditionally I understood the email sending event and logic, all your advices worked.