Page 1 of 1

email opt-out ideas?

Posted: Wed Jul 17, 2002 5:36 am
by martin
Hi all.
Any tips on an email opt-out script. Any insight into pitfalls I should avoid would be great. I have a db field with a switch of Y(es) N(o) in readyness.
Thanks,
Martin

Mailbots

Posted: Tue Jul 23, 2002 5:02 pm
by musashi
Are you looking to create a mailbot? That is a script that auto-handles certain types of email received on the server. The most common example of this is Networksolutions handling of domain issues.

If this is what you want to do, you need to get ready for some work (and fun).

The steps are as follows:

1. Create a new user (Ex: unsubscribe)
2. Create a .forward file in the user account and pipe mail into a php script
3. Create a php script (assuming you've got a cgi version of php, if not, just compile one. It can co-exist with the apache module)

Step 1 is accomplished as follows:

adduser unsubscribe

you need to also set a password for the user.

passwd unsubscribe

Step 2:

pico /home/unsubscribe/.forward

Enter the following:

\unsubscribe,"|unsubscribe.php"

Step 3: you are going to need a shebang
#!/usr/local/bin/php -q
<?php
//read in the message from the command line (sent to us by the pipe)
$message = $argv[1];

//split the message by EOL to parse the header
$messageList = split("\n",$message);

//got to read in the headers to see what kind of email we are looking at
foreach($messageList as $line)
if(preg_match("(^[\w\-\.]+):\s*(.*\S)\s*$",$line,$match))
$mailheader[$match[1]] = $match[2];

//if we are not reading an unsubscribe request... exit
if(!eregi("unsubscribe",$mailheader[subject])) exit;

//now it is time to remove the user from the db...

//Database connection
$dblink = mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($db,$dblink);

//remove user
mysql_query("
DELETE FROM SPAM_LIST
WHERE email_address = '$mailheader[reply]'
",$dblink);

mysql_close($dblink);

//You could send one more confirmation email to them
mail($mailheader[reply],"You have been removed","Your message here");


?>



You might need to fiddle with it a bit, but that should get you started. Hope that helps.