[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Unsubscribe Email

Posted on 2011-02-11
3
Medium Priority
?
508 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 1000 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to count occurrences of each item in an array.
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 …
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

872 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