Solved

Unsubscribe Email

Posted on 2011-02-11
3
496 Views
Last Modified: 2012-08-13
Many web sites have an "unsubscribe@abc.com" as a way for people to "opt out" of being sent emails.

I want to set that up on a site & "intercept" with a php script ant emails sent to "unsubscribe" & manage them with some programming logic.

How can I do that?
0
Comment
Question by:Richard Korts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
wwwdeveloper2 earned 250 total points
ID: 34876609
In the e-mail that is sent out include a link to your scripted page with a query string containing the e-mail address to be unsubscribed.

Such as yoursite.com/unsubscribe.php?email=somebody@e-mail.com

In the unsubscribe.php file use a get to grab the email address from the query string.

$_GET['email'];

Run your SQL to update your database to either remove the e-mail account from your e-mail list or flag it as no longer wanting to receive e-mails.
0
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 34876631
What server are you running your php on?  Here is a good tutorial to achieve what you want to do:

http://thedrupalblog.com/configuring-server-parse-email-php-script

Basically you need to parse the e-mail received to grab the sending e-mail address.....then do your php logic.

0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 34878471
The thing you're describing is called an email pipe script.  It is started automatically when emails sent to the pipe address are received.

Here is a teaching example of how I have implemented the email pipe in the past.  There is a little work to do because the pipe script might not be in your web root directory tree (to prevent accidental triggering).  If you put it outside of the WWW root, you will want to look carefully at the variables in phpinfo() to be sure that your access to files and data bases is correctly structured.

In this teaching example, the moving parts would start at line 55.  You would parse the $raw_email variable, extract the "from" address and the unsubscribe signal string, (make sure they match so you do not have a security exposure) and update the data base.  A nice touch might be to respond with an automated email that says, "You have been unsubscribed."

If you get an unsubscribe notice that does not contain a valid email address or that does not contain a matching signal string, do not respond to it.  Discard it silently.  A response to a bogus unsubscribe notice is a sure way to get your site branded as a spammer!
#!/usr/bin/php -q
<?php // /email_pipe/index.php


// THIS IS AN EMAIL PIPE SCRIPT.
// THIS SCRIPT IS STARTED AUTOMATICALLY FOR EACH MESSAGE.
// NOTE THAT THIS SCRIPT IS ABOVE THE /public_html/ DIRECTORY TO PREVENT ACCIDENTAL EXECUTION


// --> HOW DO WE KNOW WHICH EMAIL MESSAGES GET SENT HERE?
// THIS SCRIPT RECEIVES MESSAGES SENT TO email_pipe@your.org
// CREATE AN EMAIL MAILBOX EXCLUSIVELY FOR AUTOMATED PROCESSING.
// SET UP AN EMAIL FORWARD FOR THAT MAILBOX IN cPANEL->EMAIL LIKE THIS:
// 1...5...10...15...20...25...
// |/home/{account}/email_pipe/index.php


// --> WHEN YOU UPLOAD, THIS SCRIPT WILL BE MARKED RW-R-R BUT THAT IS WRONG
// THIS SCRIPT MUST BE MARKED EXECUTABLE x0755
// YOU CAN USE FTP SOFTWARE TO CHMOD TO RWX-RX-RX


// --> NOTE THE FIRST LINE OF THIS SCRIPT MUST SAY #!/usr/bin/php -q STARTING IN COLUMN ONE
// 1...5...10...15...20...25...
// #!/usr/bin/php -q
// <?php ... PROGRAM CODE FOLLOWS


error_reporting(E_ALL);

// USE THE OUTPUT BUFFER - THIS DOES NOT HAVE BROWSER OUTPUT
ob_start();

// COLLECT THE INFORMATION HERE
$raw_email = '';


// TRY TO READ THE EMAIL FROM STDIN
if (!$stdin = fopen("php://stdin", "R"))
{
    echo "ERROR: UNABLE TO OPEN php://stdin \n";
}

// ABLE TO READ THE MAIL
else
{
    while (!feof($stdin))
    {
        $raw_email .= fread($stdin, 4096);
    }
    fclose($stdin);
}


// REMOVE MULTIPLE BLANKS - AND OTHER PROCESSING AS MIGHT BE NEEDED
$raw_email = preg_replace('/ +/', ' ', $raw_email);

// SPEW WHAT WE GOT, IF ANYTHING, INTO THE OUTPUT BUFFER
var_dump($raw_email);

// CAPTURE THE OUTPUT BUFFER AND SEND IT TO SOMEONE ELSE VIA EMAIL
$buf = ob_get_contents();
mail ('you@your.org', 'EMAIL PIPE DATA', $buf);
ob_end_clean();

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question