newsletter plugin error when encountering null email addresses

paypal1352

New Member
YetiShare User
Wurlie User
Mar 2, 2012
297
2
0
I noticed an issue when attempting to send a newsletter and the plugin encounters a null email caused by the social plugin email registering a user but not adding their email address,

i believe i have a solution, although i have to test it further,

in file pluginNewsletters.class.php, replace the getRecipients function with this one.

public function getRecipients($userGroup, $includeUnsubs = false)
{
// setup database
$db = Database::getDatabase();

$clause = '';
switch($userGroup)
{
case 'free only':
$clause = 'level_id = 1 && email != ""';
break;
case 'premium only':
$clause = 'level_id = 2 && email != ""';
break;
case 'moderator only':
$clause = 'level_id = 10 && email != ""';
break;
case 'admin only':
$clause = 'level_id = 20 && email != ""';
break;
default:
// all registered
$clause = '1=1';
break;
}

$sQL = 'SELECT * FROM users WHERE '.$clause;
if($includeUnsubs == false)
{
$sQL .= ' AND id NOT IN (SELECT user_id FROM plugin_newsletter_unsubscribe)';
}

return $db->getRows($sQL);
}
 

enricodias4654

Member
YetiShare User
Jan 13, 2015
411
1
16
You can use "IS NOT NULL" to select emails that are not null.

public function getRecipients($userGroup, $includeUnsubs = false)
{
// setup database
$db = Database::getDatabase();

switch($userGroup)
{
case 'free only':
$clause = 1;
break;
case 'premium only':
$clause = 2;
break;
case 'moderator only':
$clause = 10;
break;
case 'admin only':
$clause = 20;
break;
default:
$clause = '';
}

if (!empty($clause)) $clause = 'level_id = '.$clause.' AND ';

$sQL = 'SELECT * FROM users WHERE '.$clause.' email IS NOT NULL ';
if (!$includeUnsubs) $sQL .= ' AND id NOT IN (SELECT user_id FROM plugin_newsletter_unsubscribe)';

return $db->getRows($sQL);
}
 

paypal1352

New Member
YetiShare User
Wurlie User
Mar 2, 2012
297
2
0
noticed another issue with the newsletter plugin, replacement [[[level]]] doesn't work, tried to fix it but no matter what the email sends [[[level]]] instead of the actual user level