TalkVirginia
03-14-2010, 11:42 AM
I'm working on an addon and one of the features is that I'm trying to detect and trap bounced emails. I found a tutorial that walks through setting this up at the following page:
http://forums.theplanet.com/lofiversion/index.php/t89873.html
I'd like to run the following script on my shared host, but I'm not sure what vBulletin scripts I would need to include to allow me to add information from the bounced emails into my vbulletin database log table. Any suggestions?
#!/usr/local/bin/php -q
<?php
// Reading in the email
$fd = fopen("php://stdin", "r");
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// Parsing the email
$lines = explode("\n", $email);
$stillheaders=true;
for ($i=0; $i < count($lines); $i++) {
if ($stillheaders) {
// 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 {
// not a header, but message
break;
// Optionally you can read out the message also, instead of the break:
//$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$stillheaders = false;
}
}
list($part1,$dum1) = explode("-bounce@yoursite.com", trim($to) );
list($dum2,$user) = explode("user-", $part1);
//
// $user now contains the user id "12345" in the example
//
// Here you put in your custom code
// like open up your database connection and
// mark the user as invalid email address,
// so you don's send to him again.
return true;
?>
http://forums.theplanet.com/lofiversion/index.php/t89873.html
I'd like to run the following script on my shared host, but I'm not sure what vBulletin scripts I would need to include to allow me to add information from the bounced emails into my vbulletin database log table. Any suggestions?
#!/usr/local/bin/php -q
<?php
// Reading in the email
$fd = fopen("php://stdin", "r");
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// Parsing the email
$lines = explode("\n", $email);
$stillheaders=true;
for ($i=0; $i < count($lines); $i++) {
if ($stillheaders) {
// 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 {
// not a header, but message
break;
// Optionally you can read out the message also, instead of the break:
//$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$stillheaders = false;
}
}
list($part1,$dum1) = explode("-bounce@yoursite.com", trim($to) );
list($dum2,$user) = explode("user-", $part1);
//
// $user now contains the user id "12345" in the example
//
// Here you put in your custom code
// like open up your database connection and
// mark the user as invalid email address,
// so you don's send to him again.
return true;
?>