Skip to content

Instantly share code, notes, and snippets.

@craigjbass
Last active January 2, 2016 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigjbass/8222061 to your computer and use it in GitHub Desktop.
Save craigjbass/8222061 to your computer and use it in GitHub Desktop.
Email_Service_Premailer
<?php
class Email_Service_Premailer {
/**
* Process using premailer
*
* requires:
* yum -y install ruby rubygems ruby-devel
* gem install premailer
* gem install hpricot
*
* @see https://github.com/premailer/premailer/
*
*
* @param string $string
* @return string
*/
public function process( $string )
{
$process = proc_open( '/usr/bin/env premailer', [ ['pipe','r'], ['pipe','w'], ['pipe','a'] ], $pipes, '/tmp' );
if( is_resource( $process ) ) {
fwrite( $pipes[0], $string );
fclose( $pipes[0] );
$processed = stream_get_contents( $pipes[1] );
fclose( $pipes[1] );
fclose( $pipes[2] );
proc_close( $process );
}
return empty( $processed ) ? $string : $processed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment