Last active
August 29, 2015 14:00
-
-
Save lyoshenka/11307631 to your computer and use it in GitHub Desktop.
Script to send out secret santa assignments
This file contains hidden or 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
#!/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