Skip to content

Instantly share code, notes, and snippets.

@lyoshenka
Last active August 29, 2015 14:00
Show Gist options
  • Save lyoshenka/11307631 to your computer and use it in GitHub Desktop.
Save lyoshenka/11307631 to your computer and use it in GitHub Desktop.
Script to send out secret santa assignments
#!/usr/bin/php
<?php
// santa file has the following format
//
// name1 [email protected]
// another name [email protected]
// etc...
$myEmail= 'YOUR EMAIL HERE';
$ppl = explode("\n", trim(file_get_contents('santa')));
$names = [];
$emails = [];
foreach ($ppl as $person) {
$name = trim(substr($person, 0, strrpos($person, ' ')));
$names[] = $name;
$emails[$name] = trim(substr($person, strrpos($person, ' ')));
}
shuffle($names);
$lastName = $names[count($names)-1];
$assignments = [];
foreach($names as $name) {
$assignments[$lastName] = $name;
$lastName = $name;
}
$headers = [
// "From: Name <email@domain>",
"Reply-To: $myEmail"
];
foreach($assignments as $santa => $recip) {
$message = "Hey $santa. Your secret santa assignment is $recip. Please get him or her wasted. Reminder: $X suggested booze price. LINK TO DOC.";
mail($emails[$santa], 'Your Booze Secret Santa Assignment', $message, implode("\r\n",$headers));
}
unset($assignments[array_search('Grin', $assignments)]);
mail($myEmail, 'Secret Santa Master List', var_export($assignments, true));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment