Created
March 28, 2015 11:56
-
-
Save markormesher/33b7f23731748e63ce96 to your computer and use it in GitHub Desktop.
KCL Tech Election PIN Sender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// init mailer | |
require('/usr/share/php/Mail.php'); | |
$factory =& Mail::factory('smtp', | |
array( | |
// SMTP auth info removed | |
) | |
); | |
$headers['From'] = 'Mark Ormesher <[email protected]>'; | |
$headers['Subject'] = 'Your Election PIN'; | |
// targets | |
$emails = []; // email list removed | |
// pins | |
$pins = []; | |
foreach ($emails as $e) { | |
// generate pin (must be unique) | |
do { | |
$pin = strtoupper(md5($e . rand(1,1000000))); | |
$pinChunk = rand(0,25); | |
$pin = substr($pin, $pinChunk, 6); | |
} while (in_array($pin, $pins)); | |
$pins[] = $pin; | |
// send pin | |
$headers['To'] = $e; | |
$sending = $factory->send($headers['To'], $headers, 'Your election PIN is ' . $pin . '. Please check the KCL Tech Slack if you don\'t know what this is.'); | |
if ($sending) { | |
echo('Sent to ' . $e . '<br />'); | |
} else { | |
echo('Failed to send to ' . $e . '<br />'); | |
} | |
} | |
// randomly re-order | |
shuffle($pins); | |
echo('The following PINs were issued:<br />'); | |
echo(implode(', ', $pins)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment