Jump to content

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"

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.