Page 1 of 1

How To Dynamically Add Unsubscribe Link?

Posted: Sat Sep 06, 2008 12:24 am
by jbh
Hey,

Forgive me but I could not find it in the wiki docs and only found one potential solution in the search function.

What is the surest way to get an unsubscribe link to work in this? Below is the code that I use, without fail, to send a message to each person in my database. I just want to append an unsubscribe link successfully.

Code: Select all

 
 
# Connect stuff
 
$title=$_POST["title"];
$table=$_POST["table"];
 
$emailmessage=$_POST["message"];
$subject=$_POST["subject"];
 
$emailmessage = wordwrap($emailmessage, 64, "\n");
$emailmessage=stripslashes($emailmessage);
$message =& new Swift_Message($subject, $emailmessage);
$myemail="support@techiehowto.com";
 
# DB Stuff is in config file
include("config.php");
 
$sql="
SELECT paypalemail from $table where title='$title'
";
 
$result = @MYSQL_QUERY($sql);
while ($row = mysql_fetch_assoc($result))
{
 
$email=$row["paypalemail"];
$email=trim($email);
$emailmessage=str_replace("[email]",$email,$emailmessage);
 $message->setSubject($subject);
$emailmessage=str_replace("[email]",$email,$emailmessage);
 
// THIS IS where I want to have something like
 
// $emailmessage.="http://www.mysite.com/unsubscribe.php?email=$email";
 
 $swift->send($message, $email, $myemail);
 
}
 
 

Re: How To Dynamically Add Unsubscribe Link?

Posted: Sun Sep 07, 2008 11:42 am
by bruno_mac
Hey!

That part doesn't have anything to do with Swift. You have to add your unsubscribe link to your message email body, or append it to the end of the email.

You need to have a 'status' field on your table with the addresses, so you will only send emails to addresses with status '1', for example. Status '0' would be unsubscribed. So your $sql below would change to:

Code: Select all

 
$sql="SELECT paypalemail from $table where title='$title' AND status=1 ";
 
Your unsubscribe.php file would be something like this (this is just a very simple example):

Code: Select all

 
$email = $_GET['email'];
 
; now we change the status on the database for that user:
$sql = "UPDATE $table SET status=0 WHERE paypalemail=$email";
$execute = mysql_query($sql) or die (mysql_error());
 
That should do it. Hope this helps.
Bruno.

Re: How To Dynamically Add Unsubscribe Link?

Posted: Tue Sep 09, 2008 8:46 am
by jbh
HI Bruno

TY for the reply. However, while I can create a static unsubscribe, I was hoping to create one that appends
their email address so one click can allow them to unsubscribe, as opossed to them having to manually do it.

If anything, it'd help me master the ability to personalize. Is this possible? I just want to make the unsubscribe
process as simple as possible and create the best user experience possible.

Re: How To Dynamically Add Unsubscribe Link?

Posted: Tue Sep 16, 2008 3:42 pm
by jbh
Nobody has a working version of this used in a professional setting?

Ok, I'll share the code when I figure it out. I think it's a pretty important part of doing business.

Re: How To Dynamically Add Unsubscribe Link?

Posted: Thu Sep 25, 2008 5:14 am
by Wardy666
if in your email you used the swift decorator plugin to append an email or unique ID number to a url on your server that contained the unsubscribe code Bruno posted below it would work as i think you wish.

such as:

Code: Select all

http://yourdomain/unsubscribe.php?email={email} 
in the footer of your email