Skip to content

Instantly share code, notes, and snippets.

@Znote
Last active September 25, 2019 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Znote/b957afbd71ddc85418cf9f163336586e to your computer and use it in GitHub Desktop.
Save Znote/b957afbd71ddc85418cf9f163336586e to your computer and use it in GitHub Desktop.
Send an email to all registered accounts on Znote AAC.
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';
// https://otland.net/threads/znote-send-email-to-all-registered-accounts.266455/
protect_page();
admin_only($user_data);
$email_list = array();
$development_mode = (!isset($_GET['RUN'])) ? true : false;
$development_SQL = ($development_mode) ? "AND `a`.`id`='{$session_user_id}'" : '';
// Load all accounts
$accounts = mysql_select_multi("
SELECT
`a`.`name`,
`a`.`email`
FROM `accounts` AS `a`
INNER JOIN `znote_accounts` AS `za`
ON `a`.`id` = `za`.`account_id`
WHERE `za`.`active` = 1
AND `a`.`email` LIKE '%@%'
{$development_SQL}
");
// Create variables to use in email body text
$OT_name = $config['site_title'];
$website_URL = $config['site_url'];
$shop_URL = $config['site_url'] . "/shop.php";
// Intiialize PHP email client
$mailer = new Mail($config['mailserver']);
// Email title
$title = "{$OT_name}: Christmas Update, double xp weekend and shop sale!";
// Loop through all accounts
foreach ($accounts as $account):
$username = $account['name'];
$email = $account['email'];
$email_list[] = $email;
// Email body
$body = "<h1>Christmas Update</h1>
<p>A new christmas update with lots of cool new stuff implemented!</p>
<p>To celebrate the christmas update, we are also activating a double xp weekend!</p>
<p>Head on over to <a href='{$website_URL}'>{$website_URL}</a> for more information.</p>
<h2>Special christmas sale!</h2>
<p>We are currently having a christmas sale, with a 20% discount on all shop items!</p>
<hr><p>I am an automatic no-reply e-mail. Any emails sent back to me will be ignored.</p>
";
// Send email
$mailer->sendMail($email, $title, $body, $username);
endforeach;
?>
<p><strong>Development mode: </strong><?php echo ($development_mode) ? 'Yes. Only sending email to admin account.' : 'No. Trying to send to everyone.'; ?></p>
<?php if ($development_mode): ?>
<p>If email looks good and you are ready to send mass mail, click <a href="?RUN=true">RUN MASS EMAIL</a>.</p>
<?php endif;
data_dump($email_list, false, "Emails sent to these addresses:");
include 'layout/overall/footer.php'; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment