Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/php -q
- <?php
- /*
- -- PIPE : "|/home/u0047/domains/krisa.be/public_html/112/pipe.php"
- -- DB
- CREATE TABLE IF NOT EXISTS `email_log` (
- `id` int(11) NOT NULL auto_increment,
- `to` varchar(100) NOT NULL,
- `subject` varchar(200) NOT NULL,
- `from` varchar(100) NOT NULL,
- `headers` text NOT NULL,
- `message` text NOT NULL,
- `source` text NOT NULL,
- `logged_at` timestamp NOT NULL default CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM;
- */
- // Config
- $dbuser = '';
- $dbpass = '';
- $dbname = '';
- $dbhost = 'localhost';
- $notify = 'kris@mymail.ext'; // an email address required in case of errors
- $FROMCHECK = 'astrid_pager_on3kdr@telenet.be'; // vanwaar de mail mag komen, andere worden genegeerd
- // read from stdin
- $fd = fopen("php://stdin", "r");
- $email = "";
- while (!feof($fd))
- $email .= fread($fd, 1024);
- fclose($fd);
- // handle email
- $lines = explode("\n", $email);
- // empty vars
- $from = "";
- $subject = "";
- $headers = "";
- $message = "";
- $splittingheaders = true;
- for ($i=0; $i < count($lines); $i++) {
- if ($splittingheaders) {
- // this is a header
- $headers .= $lines[$i]."\n";
- // look out for special headers
- if (preg_match("/^Subject: (.*)/", $lines[$i], $matches))
- $subject = $matches[1];
- if (preg_match("/^From: (.*)/", $lines[$i], $matches))
- $from = $matches[1];
- if (preg_match("/^To: (.*)/", $lines[$i], $matches))
- $to = $matches[1];
- }
- else
- $message .= $lines[$i]."\n";
- if (trim($lines[$i])=="") {
- // empty line, header section has ended
- $splittingheaders = false;
- }
- }
- preg_match('/<(.*)>/', $from, $regexfrom);
- $fromt = str_replace(array('<', '>'), '', $from);
- if ( $fromt == $FROMCHECK OR $regexfrom[1] == $FROMCHECK ) // only allow from one e-mail address
- {
- if ($conn = @mysql_connect($dbhost,$dbuser,$dbpass)) {
- if(!@mysql_select_db($dbname,$conn))
- mail($email,'Email Logger Error',"There was an error selecting the email logger database.\n\n".mysql_error());
- $from = mysql_real_escape_string($from);
- $to = mysql_real_escape_string($to);
- $subject = mysql_real_escape_string($subject);
- $headers = mysql_real_escape_string($headers);
- $message = mysql_real_escape_string($message);
- $email = mysql_real_escape_string($email);
- $double = mysql_query("SELECT subject FROM email_log WHERE subject='".$subject."'");
- if ( mysql_num_rows($double) == 0 )
- $result = @mysql_query("INSERT INTO email_log (`to`,`from`,`subject`,`headers`,`message`,`source`) VALUES('$to','$from','$subject','$headers','$message','$email')");
- }
- else
- mail($notify,'Email Logger Error',"There was an error connecting the email logger database.\n\n".mysql_error());
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement