Skip to content

Instantly share code, notes, and snippets.

@favrik
Created August 13, 2011 01:54
Show Gist options
  • Save favrik/1143379 to your computer and use it in GitHub Desktop.
Save favrik/1143379 to your computer and use it in GitHub Desktop.
Beanstalk post-commit hook script that sends an email if a specific file was modified
<?php
$SEND_NOTIFICATION = FALSE;
$watched_file = 'file/to/watch/in_your_repository';
/*----------------------------------------------------------*/
if (isset($_POST['commit'])) {
require 'JSON.php'; // PECL script, or perhaps json_decode() is enough
$parser = new Services_JSON();
$commit = $parser->decode($_POST['commit']);
foreach ($commit->changed_files as $file) {
if ($file[0] == $watched_file) {
$SEND_NOTIFICATION = TRUE;
break;
}
}
}
if ($SEND_NOTIFICATION) {
require 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer(TRUE);
$mail->IsSMTP();
$mail->Host = 'ssl://smtp.gmail.com:465';
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = ""; // SMTP password
$mail->SetFrom('[email protected]', 'Example');
$mail->AddAddress('address@example', 'Example Address');
$mail->Subject = 'The Subject';
$mail->Body = 'The message body';
try {
$mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment