Last active
February 25, 2016 10:19
-
-
Save hansspiess/f78b07cc521341d74509 to your computer and use it in GitHub Desktop.
Script for sending E-Mails from Localhost for testing purposes. More (german language) at http://www.hansspiess.de/html-e-mail-entwicklung-und-testing-mit-foundation-for-emails-gmail-und-postfix/698/
This file contains 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
<?php | |
// get args from command line | |
// http://stackoverflow.com/questions/6826718/pass-variable-to-php-script-running-from-command-line | |
if ( defined('STDIN') ) { | |
$dir = $argv[1] ? $argv[1] : './'; | |
$ext = $argv[2] ? $argv[2] : 'html'; | |
} else { | |
die( 'not on a local machine.' ); | |
} | |
// set mail vars | |
$recipients = array( 'mail@gmail.com', 'mail@anotherservice.com', 'mail@yourdomain.com' ); | |
$sender = 'mail@yourdomain.com'; | |
$reply = 'mail@yourdomain.com'; | |
$header = 'MIME-Version: 1.0' . "\r\n"; | |
$header .= 'Content-type: text/html; charset=utf-8' . "\r\n"; | |
$header .= 'From: ' . $sender . "\r\n"; | |
$header .= 'Reply-To: ' . $reply . "\r\n"; | |
// loop over files in given directory: | |
// http://is.php.net/manual/en/function.glob.php | |
foreach ( glob( $dir . '*.' . $ext ) as $file ) { | |
// set subject to a unique still readable string to be found easily in the inbox | |
$subject = time() . ' ' . $file; | |
// grab content of inlined file | |
$body = file_get_contents( $file ); | |
// and of we go! | |
foreach ( $recipients as $recipient ) { | |
mail( $recipient, $subject, $body, $header ); | |
} | |
} |
This file contains 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
{ | |
"scripts": { | |
"mail" : "php mail.php ./dist/ html" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment