dopetalk does not endorse any advertised product nor does it accept any liability for it's use or misuse

This website has run out of funding so feel free to contribute if you can afford it (see footer)

Author Topic: Last Online Email Batch Job  (Read 251 times)

Offline Chip (OP)

  • Server Admin
  • Hero Member
  • *****
  • Administrator
  • *****
  • Join Date: Dec 2014
  • Location: Australia
  • Posts: 6493
  • Reputation Power: 0
  • Chip has hidden their reputation power
  • Gender: Male
  • Last Login:Today at 05:48:14 PM
  • Deeply Confused Learner
  • Profession: IT Engineer
Last Online Email Batch Job
« on: June 22, 2021, 06:23:35 PM »
Here is a handy batch approach to notify idle members

<?php
$servername 
"localhost";
$username "dbuser";
$password "dbpasswordi";
$dbname "smf";
$tbpref "smf_";

// SET THESE !
$days_not_logged_in 365;
$do_email 0;
// ---------

$connect = new mysqli($servername$username$password$dbname);
if (
$connect->connect_error) {
        die(
"Connection failed: " $connect->connect_error);
}

$sql "SELECT * FROM" " " $tbpref "members ORDER BY last_login";

$result $connect->query($sql);

if (
$result->num_rows 0) {
        while(
$row $result->fetch_assoc()) {
                if (!empty(
$row["last_login"])) {
                        
$dateSin =  $row["last_login"];
                        
$current_date date("U"/* to have it in microseconds */;
                        
$your_month date("m"$dateSin);
                        
$your_day =  date("d"$dateSin);
                        
$your_year =  date("Y"$dateSin);
                        
$selected_date_stamp mktime(0,0,0,$your_month,$your_day,$your_year);
                        
$selected_date date("U",$selected_date_stamp);
                        
$difference round (($current_date $selected_date)/(3600*24));
                        if (
$difference >= $days_not_logged_in) {
                                echo 
$row["member_name"] . " " $row["email_address"] . " " "posts=" $row["posts"] . " ";
                                echo 
"Last logged in" " " $difference " " "days ago" PHP_EOL;
                                
$to_member =  $row["member_name"];
                                
$from_name "SMF Administrator";
                                
$from_email "smfadmin@forum.drugs-and-users.org";
                                
$headers "From: $from_name <$from_email>";
                                
$body "Dear $to_member, \n
We miss you as you have not logged in to https://forum.drugs-and-users.org for over 
$difference days. \n
Your membership is safe however you may be deleted from the forum some time in the future if you remain inactive.
Of course you will be given ample warning should that be the case. \n
Come and visit us if you're bored :-) \n
Regards, \n
Chip (Server Admin)"
;
                                
$subject "Regarding your last login to dopetalk/D&U";
                                
$to_email $row["email_address"];
                                if (
$do_email) {
                                        if (
mail($to_email$subject$body$headers)) {
                                                echo 
"(email sent)" " ";
                                        } else {
                                                echo 
"email failed" " ";
                                        }
                                }
                        }
                }
        }
} else {
        echo 
"0 results";
}

$connect->close();
?>

« Last Edit: June 25, 2021, 10:08:51 AM by Chip »
I do not condone or support any illegal activities. All information is for theoretical discussion and wonder.
All activities discussed are considered fictional and hypothetical. Information of all discussion has been derived from online research and in the spirit of personal Freedom.

Tags:
 


dopetalk does not endorse any advertised product nor does it accept any liability for it's use or misuse





TERMS AND CONDITIONS

In no event will d&u or any person involved in creating, producing, or distributing site information be liable for any direct, indirect, incidental, punitive, special or consequential damages arising out of the use of or inability to use d&u. You agree to indemnify and hold harmless d&u, its domain founders, sponsors, maintainers, server administrators, volunteers and contributors from and against all liability, claims, damages, costs and expenses, including legal fees, that arise directly or indirectly from the use of any part of the d&u site.


TO USE THIS WEBSITE YOU MUST AGREE TO THE TERMS AND CONDITIONS ABOVE


Founded December 2014
SimplePortal 2.3.6 © 2008-2014, SimplePortal