Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple PHP script to invite slack users
* This is a simple script to invite users to your slack
* Replace the subdomain and token in the variables below.
* Upload a logo called "logo.png" to the same directory for your group
* Upload a logo called "slack.png" to the same directory for slack
<link href='' rel='stylesheet' type='text/css'>
<body style="background-color: #252525; width: 100%">
<div style="text-align: center; margin-top: 75px">
<img src="logo.png" style="width: 150px; height: 150px;" />
<img src="slack.png" style="width: 150px; height: 150px;" />
<h2 style="font-family: 'Roboto', sans-serif; color: #ffffff">Join <?=SUBDOMAIN?> on Slack!</h2>
$showform = false;
$error = false;
if (isset($_POST['first'])){
if (strlen($_POST['first']) > 1 && strlen($_POST['last']) > 1 && strlen($_POST['mail']) > 5){
} else {
$showform = true;
$error = true;
} else {
$showform = true;
if ($showform){
if ($error){
<p style="font-family: 'Roboto', sans-serif; color: #9d3d3d">
Please fill in all fields
function sendForm(){
$email = $_POST['mail'];
$first = $_POST['first'];
$last = $_POST['last'];
$fields = array(
'email' => urlencode($email),
'first_name' => urlencode($first),
'token' => TOKEN,
'set_active' => urlencode('true'),
'_attempts' => '1'
// url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
// open connection
$ch = curl_init();
// set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $slackInviteUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
// exec
$replyRaw = curl_exec($ch);
if($reply['ok']==false) {
echo '<p style="font-family: \'Roboto\', sans-serif; color: #9d3d3d">';
echo 'Something went wrong, try again!';
echo '</p>';
else {
echo '<p style="font-family: \'Roboto\', sans-serif; color: #719E6F">';
echo 'Invited successfully. Check your email. It should arrive within a couple minutes';
echo '</p>';
// close connection
function showForm(){
<form method="post">
<p style="font-family: 'Roboto', sans-serif; color: #ffffff">
First Name
<input type="text" name="first" style="width: 250px; " <?php echo strlen($_POST['first']) > 0 ? 'value="'.$_POST['first'].'"' : ''; ?> />
<p style="font-family: 'Roboto', sans-serif; color: #ffffff">
Last Name
<input type="text" name="last" style="width: 250px; " <?php echo strlen($_POST['last']) > 0 ? 'value="'.$_POST['last'].'"' : ''; ?> />
<p style="font-family: 'Roboto', sans-serif; color: #ffffff">
Email address
<input type="text" name="mail" style="width: 250px; " <?php echo strlen($_POST['mail']) > 0 ? 'value="'.$_POST['mail'].'"' : ''; ?> />
<input type="submit" value="Sign me up!" />

This comment has been minimized.

Copy link

@ghost ghost commented Jan 31, 2016

Not working anymore. They added some variables. Kind of token key
Update: It working, on a server but not in localhost.

If you ever come to Cluj-Napoca I will make sure you get a beer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment