Jump to content

Email forwarding Program


j5uh

Recommended Posts

try the following:

 

function get_string_between($string, $start, $end){
        $string = " ".$string;
        $ini = strpos($string,$start);
        if ($ini == 0) return "";
        $ini += strlen($start);   
        $len = strpos($string,$end,$ini) - $ini;
        return substr($string,$ini,$len);
}

$email = get_string_between($email, "<div class=3DSection1>", "</div>");

 

Link to comment
Share on other sites

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

ok one more issue. now I've stuck in some code to pull the email addresses from the db, but im getting this error here:

 

Fatal error: Cannot redeclare get_string_between() (previously declared in /home/newhost/public_html/asd/asd/mailer3.php:28) in /home/newhost/public_html/asd/asd/mailer3.php on line 28

 

here's the code I am using:

 

#!/usr/bin/php

<?php

 

$db_host = "asd";

$db_user = "asd";

$db_pwd = "asd";

$db_name = "asd";

$db_table = "users";

$db_emailfield = "email";

 

mysql_connect($db_host, $db_user, $db_pwd);

mysql_select_db($db_name);

 

$sql = "SELECT `$db_emailfield` FROM `$db_table`;";

$result = mysql_query($sql);

while($row = mysql_fetch_assoc($result)){

$emails = $row['email'];

$ChangeTo = 'asd;

 

// read from stdin

$fd = fopen("php://stdin", "r");

$email = "";

while (!feof($fd)) {

    $email .= fread($fd, 1024);

}

fclose($fd);

 

function get_string_between($string, $start, $end){

        $string = " ".$string;

        $ini = strpos($string,$start);

        if ($ini == 0) return "";

        $ini += strlen($start); 

        $len = strpos($string,$end,$ini) - $ini;

        return substr($string,$ini,$len);

}

 

$email = get_string_between($email, "<div class=3DSection1>", "</div>");

 

 

// handle email

$lines = explode("\n", $email);

 

// empty vars

$from = "";

$subject = "Expert Advisors";

$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;

    }

}

 

$headers = 'MIME-Version: 1.0' . "\n";

$headers .= 'Content-type: text/html; charset=UTF-8' . "\n";

$headers .= "From: asd";

$ForwardTo = $emails;

mail ($ForwardTo,$subject,$message,$headers);

}

?>

Link to comment
Share on other sites

I've finally figured it out. here's the final code to share it with the world.

 

#!/usr/bin/php
<?php

$db_host = "xxx";
$db_user = "xxx";
$db_pwd = "xxx";
$db_name = "xxx";
$db_table = "users";
$db_emailfield = "email";

mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);

// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);

function get_string_between($string, $start, $end){
        $string = " ".$string;
        $ini = strpos($string,$start);
        if ($ini == 0) return "";
        $ini += strlen($start);   
        $len = strpos($string,$end,$ini) - $ini;
        return substr($string,$ini,$len);
}

$email = get_string_between($email, "<div class=3DSection1>", "</div>");


// handle email
$lines = explode("\n", $email);

// empty vars
$from = "";
$subject = "your subject here";
$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;
    }
}

$sql = "SELECT `$db_emailfield` FROM `$db_table`;";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){
$emails = $row['email'];

$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\n";
$headers .= "From: your address.com";
$ForwardTo = $emails;
mail ($ForwardTo,$subject,$message,$headers);
}
?>

Link to comment
Share on other sites

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.