Nota Acap
  • Introduction
  • Linux Guide
    • Fresh Installed Centos 7
    • Changing Network Interfaces in Centos 7
    • Lockdown SSH
    • Recursively change permission Linux
    • Proxy Server IPtables
    • Provisioning Web Server with Custombuild
    • MySQL Basic Management
    • Increasing Existing LVM Disk
  • Windows Guide
  • Application Guide
    • WEB Port IPtables Rate Limit
    • Simple Email Piping Script
    • HTTP Dead
    • Email Relay Outgoing
    • Compiling Extra PHP version (Directadmin)
    • Finding the SPAM (cPanel)
    • HTTP Basic Virtual Host
    • Update Kernel for DRBD Hosts
  • Migration Related
    • Cpanel -> Cpanel (Bulk)
    • IMAPSYNC Basic Scripts
    • Directadmin -> cPanel (Copy/Sync Emails)
    • Basic Rsync Script
Powered by GitBook
On this page

Was this helpful?

  1. Application Guide

Simple Email Piping Script

#!/usr/bin/php -q
<?
$email_msg = ''; // the content of the email that is being piped
$email_addr = 'user2@bamboohillskl.com, user3@bamboohillskl.com'; // where the email will be sent
$subject = ''; // the subject of the email being sent
// open a handle to the email
$fh = fopen("php://stdin", "r");
// read through the email until the end
while (!feof($fh)){
        $email_msg .= fread($fh, 1024);
}
fclose($fh);
$lines = explode("\n", $email_msg);
$from = "";
$to = "";
$subject1 = "";
$headers = "";
$is_header= true;
//loop through each line
for ($i=0; $i < count($lines); $i++) {
if ($is_header) {
// hear information. instead of main message body, all other information are here.
$headers .= $lines[$i]."\n";
// Split out the subject portion
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject1 = $matches[1];
}
//Split out the recipient information portion
if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
$to = $matches[1];
}
//Split out the sender information portion
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// content/main message body information
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$is_header = false;
}
}
$from .= " with subject  ' $subject1 ' .\r\n";
$subject = "New Email for $to !";
// send a copy of the email to your account
mail($email_addr, $subject, "Email received from ".$from);
?>
PreviousWEB Port IPtables Rate LimitNextHTTP Dead

Last updated 4 years ago

Was this helpful?