Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4255
Latest: andreios
New This Month: 3
New This Week: 1
New Today: 0
Stats
Total Posts: 43259
Total Topics: 7518
Most Online Today: 201
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 178
Total: 178

Author Topic: Sending an email to expired group members  (Read 10236 times)

0 Members and 1 Guest are viewing this topic.

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Sending an email to expired group members
« on: June 28, 2016, 02:17:17 pm »
Hi,

I would like to send an email to members who have been removed from their membergroup as a result of expiration. I found the function, it is: CheckGroupExpire

I added this code below

Code: [Select]
removeMembersFromGroups( $row['ID_MEMBER'], $row['ID_GROUPToMove']);
Code: [Select]
removeMembersFromGroups( $row['ID_MEMBER'], $row['ID_GROUPToMove']);

$subject = 'Your membership has expired';
$message = 'Hello again,<br/>a membership you purchased on '.date('F j, Y, g:i a', $row['date']).' has expired.<br/>To continue using our premium services, visit our store at:<br/>'.$scripturl.'?action=store';
$emailAddress = '';

sendmail($emailAddress, $subject, $message, null, true);

My problem is I don't know how to obtain the customer's email address. Could you please write me a small code on how to retrieve their email address :(

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Sending an email to expired group members
« Reply #1 on: June 29, 2016, 06:40:24 pm »
For future reference, here's what I did:

Code: [Select]
loadMemberData($row['ID_MEMBER'], false, 'profile');
loadMemberContext($row['ID_MEMBER']);
$user = $memberContext[$row['ID_MEMBER']];

$subject = 'Your membership has expired!';
$message = 'Dear '.$user['username'].',<br/><br/>A membership upgrade you purchased on '.date('F j, Y, g:i a', $row['date']).' has expired.<br/><br/>To extend your service, visit our store at:<br/><br/>'.$scripturl.'?action=store';
$emailAddress = $user['email'];

sendmail($emailAddress, $subject, $message, null, true);

removeMembersFromGroups( $row['ID_MEMBER'], $row['ID_GROUPToMove']);

// Delete the log
db_query("DELETE FROM {$db_prefix}store_group_log WHERE ID = " . $row['ID'] . " LIMIT 1", __FILE__, __LINE__);

Also added:

Code: [Select]
require_once('../SSI.php');
require_once($sourcedir . '/Subs-Post.php');
require_once($sourcedir . '/Subs-Members.php');

Could you confirm if this is fine?

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Sending an email to expired group members
« Reply #2 on: June 29, 2016, 07:59:46 pm »
It looks maybe realName instead of username if you want to show their display name.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Sending an email to expired group members
« Reply #3 on: June 29, 2016, 10:55:18 pm »
It looks maybe realName instead of username if you want to show their display name.

Thanks for the pointer, feel free to add this to the next release.

But you know what would be amazing, if I could send out an email a day or two before warning the person that it's about the expire! (of course, for non-subscription purchases)

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Sending an email to expired group members
« Reply #4 on: July 03, 2016, 02:48:23 pm »
Can you tell me what I'm doing wrong here :-\ This is a modified version of the function "CheckGroupExpire".

Code: [Select]
require_once($sourcedir . '/Load.php');
require_once($sourcedir . '/Subs-Post.php');
require_once($sourcedir . '/Subs-Members.php');

$dbresult = db_query("
SELECT
ID_MEMBER, groupexpiredays, date, ID, ID_GROUPToMove
FROM {$db_prefix}store_group_log
WHERE groupexpiredays <> 0", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($dbresult))
{
if (($row['date'] +$row['groupexpiredays'] * 24 * 60 * 60) < time())
{
loadMemberData($row['ID_MEMBER'], false, 'profile');
loadMemberContext($row['ID_MEMBER']);
$user = $memberContext[$row['ID_MEMBER']];

$subject = 'Your membership has expired!';
$message = 'Dear '.$user['username'].',<br/><br/>A membership upgrade you purchased on '.date('F j, Y, g:i a', $row['date']).' has expired.<br/><br/>To extend your premium membership, visit our store:<br/><br/>'.$scripturl.'?action=store';
$emailAddress = $user['email'];

sendmail($emailAddress, $subject, $message, null, true);

removeMembersFromGroups( $row['ID_MEMBER'], $row['ID_GROUPToMove']);

// Delete the log
db_query("DELETE FROM {$db_prefix}store_group_log WHERE ID = " . $row['ID'] . " LIMIT 1", __FILE__, __LINE__);
}
}
mysql_free_result($dbresult);

The problem is that it's not sending the final email to each member. However, when I put a mock email address in place of $emailAddress, the email is actually sending when the function is activated.

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Sending an email to expired group members
« Reply #5 on: July 03, 2016, 02:54:07 pm »
Is  $user['email'] empty?

You can do a print_r($user) to see what it contains.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/
Like Like x 1 View List

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Sending an email to expired group members
« Reply #6 on: July 03, 2016, 02:59:37 pm »
When I do a mock up where I make $row['ID_MEMBER'] = 6, for example, the email address for $row['ID_MEMBER'] 6 appears correctly. This leads me to assume it is. Here's the full function I modified (from Store.php):

Code: [Select]
function CheckGroupExpire()
{
global $db_prefix, $sourcedir, $scripturl;

// Check if any group memberships from products ordered have expired.
// Only really need to check this once a day
$nexttime =  time() +  1 * 24 * 60 * 60; //Current time + a day ahead

require_once($sourcedir . '/Load.php');
require_once($sourcedir . '/Subs-Post.php');
require_once($sourcedir . '/Subs-Members.php');

$dbresult = db_query("
SELECT
ID_MEMBER, groupexpiredays, date, ID, ID_GROUPToMove
FROM {$db_prefix}store_group_log
WHERE groupexpiredays <> 0", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($dbresult))
{
if (($row['date'] +$row['groupexpiredays'] * 24 * 60 * 60) < time())
{
loadMemberData($row['ID_MEMBER'], false, 'profile');
loadMemberContext($row['ID_MEMBER']);
$user = $memberContext[$row['ID_MEMBER']];

$subject = 'Your membership has expired!';
$message = 'Dear '.$user['username'].',<br/><br/>A membership upgrade you purchased on '.date('F j, Y, g:i a', $row['date']).' has expired.<br/><br/>To extend your premium membership, visit our store:<br/><br/>'.$scripturl.'?action=store';
$emailAddress = $user['email'];

sendmail($emailAddress, $subject, $message, null, true);

removeMembersFromGroups( $row['ID_MEMBER'], $row['ID_GROUPToMove']);

// Delete the log
db_query("DELETE FROM {$db_prefix}store_group_log WHERE ID = " . $row['ID'] . " LIMIT 1", __FILE__, __LINE__);
}
}
mysql_free_result($dbresult);

// Update the next time to check for groups expiring
updateSettings(array('store_lastgroupexpire' => $nexttime));

}
« Last Edit: July 03, 2016, 03:01:26 pm by shuban »

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16436
    • View Profile
Re: Sending an email to expired group members
« Reply #7 on: July 03, 2016, 03:05:46 pm »
I would add $memberContext to the globals list in the top of the function
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline shuban

  • Hero Member
  • *****
  • Posts: 665
    • View Profile
    • Biology Forums
Re: Sending an email to expired group members
« Reply #8 on: July 04, 2016, 08:07:46 pm »
I would add $memberContext to the globals list in the top of the function

Yes, that did it!

Thank you for your continuous support.

 

Related Topics

  Subject / Started by Replies Last post
7 Replies
7892 Views
Last post July 16, 2009, 12:22:14 am
by SMFHacks
14 Replies
12678 Views
Last post November 01, 2009, 04:14:02 am
by Vincent Volmer
3 Replies
6506 Views
Last post March 26, 2013, 01:40:57 pm
by SMFHacks
sending emails

Started by ozzie4x4 « 1 2 » Support

16 Replies
10311 Views
Last post May 27, 2013, 08:55:02 pm
by SMFHacks
7 Replies
7640 Views
Last post September 25, 2014, 10:20:12 am
by SMFHacks

+- Recent Topics

No thumbnails on new uploads by SMFHacks
March 27, 2024, 02:10:41 pm

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

an idea for new mod (( content type with different display )) by SMFHacks
February 27, 2024, 01:36:27 pm

[Mod] RSS Feed Poster by SMFHacks
February 27, 2024, 11:57:18 am

find duplicate pictures by fvlog19
February 14, 2024, 02:22:40 pm

Error uploading video. by SMFHacks
February 08, 2024, 02:04:16 pm

Gallery icon as last added image by fvlog19
February 01, 2024, 01:04:56 pm

Powered by EzPortal