All pastes #33539 Raw Edit

groogs

public php v1 · immutable
#33539 ·published 2005-12-13 17:29 UTC
rendered paste body
#!/usr/bin/php<?php/* Sendmail Wrapper 0.1By Greg Maclellan (www.gregmaclellan.com)This is a wrapper for sendmail. All you have to do is set the paths below,and set up this script to be called.For php, it means changing sendmail_path to point at this file.*/// unique message id to use for this message$messageid = uniqid("logged");// log file to write to (should use $messageid)$logfile = "/var/log/phpmail/".$messageid;// path to sendmail$sendmail = "/usr/sbin/sendmail -t -i";// additional headers$add_headers["X-MsgID"] = $messageid;// parse out the domain from the current working directory. In this case, named /home/httpd/vhosts/domain.com/if (preg_match("|/home/httpd/vhosts/([a-zA-Z0-9\._-]*)(/.*)?|", $_ENV["PWD"], $matches)) {        $add_headers["X-Generating-Domain"] = $matches[1];}/***************************************************************************** *****************************************************************************/// read STDIN (mail message)while (!feof(STDIN)) {        $data .= fread(STDIN, 1024);}// split out headerslist ($headers, $message) = explode("\n\n", $data, 2);// add additional headersif ($add_headers) {        foreach ($add_headers as $field=>$contents) {                $headers .= "\n".$field.": ".$contents;        }}// reassemble the message$data = $headers."\n\n".$message;// write to our log file$fd = fopen($logfile,"w");fwrite($fd, "Date: ".date("r")."\n");fwrite($fd, "PWD: ".$_ENV['PWD']."\n");fwrite($fd, "Msg ID: ".$messageid."\n");fwrite($fd, "\n");fwrite($fd, "Message:\n");fwrite($fd, "----------\n");fwrite($fd, $data);fclose($fd);// write to the real sendmail$h = popen($sendmail, "w");fwrite($h, $data);pclose($h);?>