Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-09-2012, 07:15 PM   PM User | #1
markman641
Regular Coder

 
Join Date: Jul 2011
Posts: 246
Thanks: 58
Thanked 1 Time in 1 Post
markman641 has a little shameless behaviour in the past
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:
Quote:
/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!
markman641 is offline   Reply With Quote
Old 10-26-2012, 12:03 AM   PM User | #2
markman641
Regular Coder

 
Join Date: Jul 2011
Posts: 246
Thanks: 58
Thanked 1 Time in 1 Post
markman641 has a little shameless behaviour in the past
Bumping this! :3
markman641 is offline   Reply With Quote
Old 10-31-2012, 11:28 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:43 PM.


Advertisement
Log in to turn off these ads.