Solved

Unsubscribe Email

Posted on 2011-02-11
3
495 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

740 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