Jump to content

[SOLVED] question on getting the info from a piped email


tryingtolearn

Recommended Posts

Im trying to gather the info from bounced emails

 

I have all the replys being sent to an email address then using a script to get the info from the bounced emails

Mainly which address it could not be delivered to

 

But the only variable I get right now is the subject, everything else is blank

 

Any ideas on what I may be doing wrong?

 

This test is just set up to email me the results

Sidenote - The imap functions looked like the way to go but it doesnt seem like that is installed on my host.

#!/usr/local/php5/bin/php
<?php
// 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];
        }

	} else {
        // not a header, but message
        $message .= $lines[$i]."\n";
    }



    if (trim($lines[$i])=="") {
        // empty line, header section has ended
        $splittingheaders = false;
    }


}
include('Mail.php');
        include('Mail/mime.php');

        // Constructing the email
        $sender = "//fromaddress";
        $recipient = "//toaddress";
        $subject = "Bounce Report";                                                // Subject for the email
        //$text = 'Bounce Report.';                                      // Text version of the email
        $html = '<html><body><p>'.$from.' - '.$subject.'</p></body></html>';      // HTML version of the email
        $crlf = "\n";
        $headers = array(
                        'From'          => $sender,
                        'Return-Path'   => $sender,
                        'Subject'       => $subject 
                        );

        // Creating the Mime message
        $mime = new Mail_mime($crlf);

        // Setting the body of the email
        $mime->setTXTBody($text);
        $mime->setHTMLBody($html);

        // Set body and headers ready for base mail class 
        $body = $mime->get();
        $headers = $mime->headers($headers);

       // SMTP params
        $smtp_params["host"] = "host"; // SMTP host
        $smtp_params["port"] = "port";//587
	$smtp_params["auth"]     = true;
        $smtp_params["username"] = "un";
        $smtp_params["password"] = "pw";
        // Sending the email using smtp
        $mail =& Mail::factory("smtp", $smtp_params); 
        $result = $mail->send($recipient, $headers, $body);
        if($result)
        {
          echo("Your message has been sent!");
        }
        else
        {
          echo("Your message was not sent: " . $result);
        }
        

?>

Got it figured out,

Wasnt the script but with the pipe I set up under the forwarder.

 

I had

"|/home/USERNAME/domains/DOMAIN_NAME/public_html/PATH/TO/SCRIPT.php"

But it needed to be

"|/usr/local/bin/php /home/USERNAME/domains/DOMAIN_NAME/public_html/PATH/TO/SCRIPT.php"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.