Solved

Unsubscribe Email

Posted on 2011-02-11
3
487 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
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
wwwdeveloper2 earned 250 total points
Comment Utility
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
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now