Facebook  Twitter 

SMFHacks.com

+- +-

SMFHacks.com

+- User Information

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

+- Forum Stats

Members
Total Members: 12389
Latest: GhostHunting
New This Month: 6
New This Week: 1
New Today: 1
Stats
Total Posts: 40330
Total Topics: 7100
Most Online Today: 83
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 49
Total: 49

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

0 Members and 1 Guest are viewing this topic.

Offline shuban

  • Hero Member
  • *****
  • Posts: 657
    • View Profile
    • Homework Clinic - Your Academic Lifeline
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: 657
    • View Profile
    • Homework Clinic - Your Academic Lifeline
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: 15159
    • 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: 657
    • View Profile
    • Homework Clinic - Your Academic Lifeline
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: 657
    • View Profile
    • Homework Clinic - Your Academic Lifeline
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: 15159
    • 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: 657
    • View Profile
    • Homework Clinic - Your Academic Lifeline
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: 15159
    • 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: 657
    • View Profile
    • Homework Clinic - Your Academic Lifeline
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
6076 Views
Last post July 16, 2009, 12:22:14 am
by SMFHacks
14 Replies
10842 Views
Last post November 01, 2009, 04:14:02 am
by Vincent Volmer
3 Replies
4492 Views
Last post March 26, 2013, 01:40:57 pm
by SMFHacks
sending emails

Started by ozzie4x4 « 1 2 » Support

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

+- Recent Topics

prettyurls - TroubleShooting.wiki by SMFHacks
Today at 04:24:47 pm

Quality of images after import by SMFHacks
September 05, 2020, 10:21:44 am

How do I download gallery images? by CWVRV
August 30, 2020, 11:50:07 pm

Deleting Empty Galleries by SMFHacks
August 30, 2020, 11:43:32 am

PHP error by davejo
August 25, 2020, 07:35:13 am

Permissions to list ads and buy items by CWVRV
August 21, 2020, 05:19:45 pm

Doubt with download permissions. by Rock Lee
August 20, 2020, 08:23:24 pm

Attachment images Upsidedown or Sideways by SMFHacks
August 18, 2020, 05:41:07 pm

[Mod]Avatars Display Integration by Hatshepsut
August 17, 2020, 11:39:54 pm

Simple Portal Block - Classifieds by SMFHacks
August 16, 2020, 09:56:48 am

Powered by EzPortal