[METHOD] Lead Capture Autoresponder with cPanel email forwarder pipe to program

Discussion in 'PHP & Perl' started by Tensegrity, Dec 24, 2011.

  1. Tensegrity

    Tensegrity Elite Member

    Apr 22, 2009
    Likes Received:
    I apologize if this has already been posted, I didn't see this listed anywhere on this forum and it's been a while since I shared any useful knowledge so I figured I'd give some of you coders some ideas if you haven't thought of it already. I decided to put this in the PHP coders section because it seems like something you guys would be interested in...

    People spend all this money on buying autoresponders and other apps when they don't realize that they actually have something free right under their noses inside cPanel. With a little time and patience, I bet you can make this method work for you real well, and maybe even turn it into some serious cash (I know I have! :D).

    Anyway, on to it...

    Let's say you're trying to capture leads for your Mega Money Making Machine product that you're planning on shilling in a couple weeks. Maybe you found a website with tons of traffic pertaining to your niche or maybe you get a lot of emails already pouring into a certain email address but you don't know what to do with them and wish you could make them opt-in to your list to ensure the quality of the leads for your MMMM blast coming up. Or maybe you are just sick of all the spam you get and wanna start backfiring them with your own offers. a.Weber is a great tool for managing a mailing list but unfortunately, you gotta get people to go through a 3 step process to get on your list. They have to:

    1) hit your platform,
    2) give you their email address and tell you they want on the list
    3) confirm the subscription.

    Thankfully cPanel not only has a filtering mechanism you can use, but a forwarding mechanism which you can use to run a script every time you get certain emails. This way you can bypass steps 1 and 2 of the a.wber opt in process. :D

    So i'll just do it step by step and the code will follow:

    1. FILTERING first, you need to set up the filtering. You can actually bypass this step if you know that every single email coming into a certain address is a potential lead. but otherwise, you may be in a position where you use your email address for important things but constantly get annoying offers for the same damn clickbank program that you know doesn't even work from a kajillion marketers, and you don't want to remove yourself from their lists cuz they have good free ebooks or other occasional gems. The solution is to use the filtering to redirect to another address which you will be using to add them to your a.weber or other opt in list :)

    So login to cPanel and do Mail > User level forwarding and select the address you get all that excess offers to, give your filter a name, give it some rules and under Actions select Redirect

    2. FORWARDING Now, you need to create a new email forwarder in cPanel (Mail > Forwarders > Add Forwarder) ... enter a new email address, something that is hard to think of so you don't get tons of spam there, like [email protected]

    3. next, click Advanced Options and select Pipe to Program. this is where it gets fun...
    create a php file in your ftp text editor (i like to use pspad) and go back to cPanel and enter in the true path to your php file. **important** make sure your php file doesn't have a Hashbang shebang at the top and when you enter the pipe to program command it should look exactly like this:
    /usr/bin/php -q /home/username/public_html/your_script.php
    Click Add Filter and it'll ask you on the next page if you want to add Hashbang at the top, click the button that says Fixup Piped Program

    4. This next part is where you write the php code that will execute whenever you get an email sent to your
    [email protected] address... obviously this can be fixed to do whatever the hell you want with it, but for the purposes of this tutorial i am just going to give you a way to sign them up to your a.weber list. After they write to you, they will get a Confirm Your Subscription email from your list.

    open up your php script and add the following after the hashbang:

    // read from stdin -- you need to read the email from the stdin program
    $fd = fopen("php://stdin", "r");
    $email = "";
    while (!feof($fd)) {
        $email .= fread($fd, 1024);
    // 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];
            if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
                $to = $matches[1];
        } else {
            // not a header, but message
            $message .= $lines[$i]."\n";
        if (trim($lines[$i])=="") {
            // empty line, header section has ended
            $splittingheaders = false;
    //a function to submit your new Lead to a.Weber
    function post_request($url, $data, $referer='') {
        // Convert the data array into URL Parameters like a=b&foo=bar etc.
        $data = http_build_query($data);
        // parse the given URL
        $url = parse_url($url);
        if ($url['scheme'] != 'http') {
            die('Error: Only HTTP request are supported !');
        // extract host and path:
        $host = $url['host'];
        $path = $url['path'];
        // open a socket connection on port 80 - timeout: 30 sec
        $fp = fsockopen($host, 80, $errno, $errstr, 30);
        if ($fp){
            // send the request headers:
            fputs($fp, "POST $path HTTP/1.1\r\n");
            fputs($fp, "Host: $host\r\n");
            if ($referer != '')
                fputs($fp, "Referer: $referer\r\n");
            fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
            fputs($fp, "Content-length: ". strlen($data) ."\r\n");
            fputs($fp, "Connection: close\r\n\r\n");
            fputs($fp, $data);
            $result = '';
            while(!feof($fp)) {
                // receive the results of the request
                $result .= fgets($fp, 128);
        else {
            return array(
                'status' => 'err',
                'error' => "$errstr ($errno)"
        // close the socket connection:
        // split the result header from the content
        $result = explode("\r\n\r\n", $result, 2);
        $header = isset($result[0]) ? $result[0] : '';
        $content = isset($result[1]) ? $result[1] : '';
        // return as structured array:
        return array(
            'status' => 'ok',
            'header' => $header,
            'content' => $content
    //set up your url to send the data to, in this case a.Weber's 'add lead' script
    $url = "http://www.aweber.com/scripts/addlead.pl";
    //set up the data to send. this can all be grabbed from a.Weber's html form code for your signup form
    $data[meta_web_form_id] = "238234719"; 
    $data[meta_split_id] = "";
    $data[listname] = "your_list_name";
    $data[redirect] = "http://www.aweber.com/thankyou-coi.htm?m=text";
    $data[meta_adtracking] = "My_Web_Form";
    $data[meta_message] = "1";
    $data[meta_required] = "email";
    $data[meta_tooltip] = "";
    //this is the email address you grabbed from the From field in the email that was sent to you!
    $data[email] = $from;
    Save it and voila! You got yourself an auto-list-signup.

    As some extra thoughts about the a.webr signup, try to remember that all you're dealing with is submitting a form. And as we all know, you don't have to actually visit a form to submit it, you just have to know what values you're submitting and where the form's action is pointing to, which obivously you can find out by looking at the HTML source when you visit a page.

    BE CAREFUL though cuz i'm sure if you get too many disinterested adds to a.Weber they will wonder whats up.

    But yea, all you gotta do is get your leads to send you an email and they get the auto-subscribe :) Not that hard if they're already spamming you to death :D You could use this great with FB, Twit, CL, etc.

    Happy Holidays :D
    • Thanks Thanks x 3
    Last edited: Dec 24, 2011
  2. KraftyKyle

    KraftyKyle Jr. Executive VIP Jr. VIP

    Aug 13, 2008
    Likes Received:
    Scraping Instagram
    Home Page:
    Great post! I'll take a closer look in a bit...
  3. ~divinci

    ~divinci Registered Member

    Sep 23, 2009
    Likes Received:
    Infastructure Reverse Engineer
    Liverpool UK
  4. Tensegrity

    Tensegrity Elite Member

    Apr 22, 2009
    Likes Received:
    wow divinci, good for you :p
  5. kboxer7

    kboxer7 Jr. VIP Jr. VIP

    Jan 25, 2010
    Likes Received:
    Quick question from a programming newb.

    I get the whole concept. They email you, you have the option to filter or not, then the script fills in the aweber form with their email and the person who owns the email address gets a "click here to confirm" subscription email from Aweber correct?

    OR...does this method auto confirm the aweber subscription without the actual owner of the email having to click on a "confirm this subscription" notifier from Aweber?

    Sorry, I hope that made sense. This might just be what I was looking for to expand on an idea I had.

    EDIT: I think I found it. You said this allows you to buypass Steps 1 and 2 of the opt in process, but NOT the confirmation step.

  6. Tensegrity

    Tensegrity Elite Member

    Apr 22, 2009
    Likes Received:
    Hey there, no problem, glad you figured it out.

    Auto-confirming is actually i.le.gal, so I wouldn't recommend that. But for educational purposes, two possible methods come to mind:
    1. spoo,f the email header but aw.ebr is probably checking the headers for spoo,fing
    2. sign people up through fake emails that forward to them so if you had, say, 1k g.mail addresses you could set up a bot to click the confirm link then forward all future emails to your list, i.e. the gma,il account is signed up, not your target.