Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    Pipe bounced email!

    Well I was working on this all day yesterday and I finally got it to work!

    Lets say you are sending out a newsletter or something to people in your DB. Chances are you are going to get some bounces. Now, why would you do nothing with these bounced emails? You should unsubscribe them from your DB or something! Here's how to do it:

    Step 1: Make a php file and call it whatever you want.
    Step 2: Paste the following code into it:

    PHP Code:
    #!/usr/local/bin/php -q
    <?php

    $con 
    mysql_connect("localhost","xxxxxxxx","xxxxxxx");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("xxxxxxx"$con);

    /* Read the message from STDIN */
    $fd fopen("php://stdin""r"); 
    $email ""// This will be the variable holding the data.
    while (!feof($fd)) {
    $email .= fread($fd1024);
    }
    fclose($fd);
    /* Script start */

    $start_limiter '-0400
    To: '
    ;
    $end_limiter 'Subject: RapidCashGPT Newsletter';
    $start_pos strpos($email,$start_limiter);
    $end_pos strpos($email,$end_limiter,$start_pos);
    $needle substr($email$start_pos+10, ($end_pos-11)-$start_pos);
    //do action here
    Step 3: Configure the following:
    1. Change your database info on lines 4 & 10
    2. On line 21/22, make sure that text appears in a bounced email. It may be different for everyone else
    3. On line 23, change the subject to whatever the subject is of the outgoing email you sent
    4. Code an action where it says //do action here. this could be a mysql query, or even writing it to a text document for later use


    Step 4: In cpanel, go to "Account Level Filtering", click Create New Filter.
    Name it whatever you like, then set up how you want them filtered. I set it up as "Subject Equals: Mail delivery failed: returning message to sender"

    Step 5: Under Actions, click pipe to program, and put this:
    /usr/bin/php -q /home/USERNAME/public_html/FILE.php
    Be sure to change "username" to your account, and "FILE" to whatever you named the php file.

    Step 6: Testing and fixing! There is only one problem with the code above, on line 26 you see 2 numerical values.. This is what deletes extra characters from the substring. When you change the start and ending limiters to fir your needs, the numbers will be off. Just play around with the numbers until you get no extra characters (or any accidentally deleted characters) at the end or beginning of the email!

    Step 7: Save everything! It will now be working. Please note that "testing" the filter does not work correctly, and nothing will happen why you try to do so. If you really want to test it, send an email to your main account with the title filter you chose and the same body as a bounced email and see if it works! Also, there may be a better way to strip the email out of the email, so be my guest to change it and let me know! You might be able to pass a header when you're sending your emails to make your life a little easier.


    Thanks would be appreciated Please let me know of any customization to this script that make it easier to use!

  • #2
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Bumping this! :3

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,364
    Thanks
    61
    Thanked 530 Times in 517 Posts
    It should be noted that this will only work on linux where email piping is available. On windows it is not possible to use piping.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •