Home Forums Newsletter Plugin Support Unsubscribtion Form

Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #15279
    fionera
    Participant

    Hello Guys

    i will make a Unsubscribtion Form but i only Fail… Here my Code:

    <div class="newsletter newsletter-unsubscription"><form action="http://www.1-night-in-paris.de/wp-content/plugins/newsletter/do/unsubscribe.php" method="post"><span style="color: #0033cc;"><span style="font-family: Verdana, serif;"><span style="font-size: large;">Newsletter-Abmeldung</span></span></span>
    <table border="0" cellspacing="0" cellpadding="3">
    <tbody>
    <tr>
    <th>Emailadresse</th>
    <td align="left"><input class="newsletter-email" name="na" required="" size="30" type="email" /></td>
    </tr>
    <tr>
    <td class="newsletter-td-submit" style="text-align: center;" colspan="2"><input class="newsletter-submit" type="submit" value="Absenden" /></td>
    </tr>
    </tbody>
    </table>
    </form></div>

    Can u help me?

    #15280
    fionera
    Participant

    Because the Code is failed in the Forum…. http://pastebin.com/Z1yny2iH

    #15281
    Stefano
    Keymaster

    There is not possible unsubscription form. When a subscriber receive the newsletter he’ll have the unsubscription link, which is a personal link.

    Stefano.

    #18433
    Anonymous
    Participant

    Little late on the response, but you could add this to your functions.php file – it makes a shortcode that shows a simple unsubscribe form:

    Code can be found here: http://pastie.org/10496351

    add_shortcode('newsletter_unsubscribe','hos_newsletter_unsubscribe');
    function hos_newsletter_unsubscribe($atts) {
    	
    	extract(shortcode_atts(array(
    		'class'	=> '',
    	), $atts));
    
    	$formcontent = '<script type="text/javascript">
    		//<![CDATA[
    		if (typeof newsletter_check !== "function") {
    			window.newsletter_check = function (f) {
    				var re = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/;
    				if (!re.test(f.elements["ne"].value)) {
    					alert("The email is not correct");
    					return false;
    				}
    				for (var i=1; i<20; i++) {
    				if (f.elements["np" + i] && f.elements["np" + i].required && f.elements["np" + i].value == "") {
    					alert("");
    					return false;
    				}
    				}
    				if (f.elements["ny"] && !f.elements["ny"].checked) {
    					alert("You must accept the privacy statement");
    					return false;
    				}
    				return true;
    			}
    		}
    		//]]>;
    		</script>
    		<div class="newsletter newsletter-unsubscription">
    		<form method="post" action="" onsubmit="return newsletter_check(this)" _lpchecked="1">
    		
    		<input type="hidden" name="form_action" value="unsubscribe">
    		<table cellspacing="0" cellpadding="3" border="0">
    		
    		<!-- email -->
    		<tbody><tr>
    			<th>Email</th>
    			<td align="left"><input class="newsletter-email" type="email" name="email_unsub" size="30" required=""></td>
    		</tr>
    		
    		<tr>
    			<td colspan="2" class="newsletter-td-submit">
    				<input class="newsletter-submit" type="submit" value="Unsubscribe">
    			</td>
    		</tr>
    		
    		</tbody></table>
    		</form>
    		</div>';
    	
    	if( "unsubscribe" == $_POST['form_action']) {
    		
    		global $wpdb;
    		$email = sanitize_email($_POST['email_unsub']);
    		$result = $wpdb->query( $wpdb->prepare( 
    			"DELETE FROM $wpdb->newsletter
    
    			 WHERE /<code>email/</code> = %s
    			",
    				$email
    			)
    		);
    		
    		if( 1 == $result ) {
                            // Unsubscribe Message
    			$content = '<h1>' . __('Successfully Unsubscribed','Newsletter') .'</h1>';
    			$content .= '<p>' . __('You have been successfully unsubscribed from our newsletter.','Newsletter') . '</p>';
    		} else {
    			$content = '<h1>' . __('Unsubscribe','Newsletter') . '</h1>';
    			$content .= '<p class="red">' . __('That email address was not found.','Newsletter') . '</p>';	
    			$content .= $formcontent;		
    		}
    	} else {
    		$content = '<h1>' . __('Unsubscribe','Newsletter') . '</h1>';
    		$content .= $formcontent;
    	}	
    	
    	return $content;
    	
    }

    Then where you want the unsubscription form place this shortcode:

    [newsletter_unsubscribe]

    The Form:
    Unsubscription Form

    • This reply was modified 6 years, 9 months ago by Anonymous. Reason: Code looked off
    • This reply was modified 6 years, 9 months ago by Anonymous. Reason: needed to escape quote marks
    • This reply was modified 6 years, 9 months ago by Anonymous.
    #18480
    DogMaDesign
    Participant

    Hello,

    I also want an unsubscribe form on my website. Not just because the unsubscribe link in the email is not working, but for the purpose that not everyone is computersmart enough to remember there is an unsubscribe link in their email.

    I tried using the code above and the shortcode works. There is an unsubscribe form in my page. But if you enter your email address, the form says: That email address was not found.

    Can you help?

    Kind regards,

    Rianne

    #18607
    EddaZ.
    Participant

    Hello,

    I’ve got the same problem. The unsubscribe form is generated by the functions.php code but does not work: “email adress not found”.
    Can’t believe there isn’t any solution to this problem?!

    I’d appreciate any help or suggestion.
    Edda

    #18792
    apandia
    Participant

    Hi,

    same for me: “email adress not found”

    Any suggestions?
    Mathias

    #18929
    Stefano
    Keymaster

    There is NOT an unsubscription form natively supported in Newsletter.

    Stefano.

    #18948
    EddaZ.
    Participant

    Sorry to hear there is no unsubscription form. (yet?)

    I am still a beginner with php and wordpress plugins.
    Otherwise I would have tried to extend the code by anonymus.
    But i can’t even figure out why the code doesn’t find the emailadress in the database.
    An when I think about it:

    There is another problem: We wouldnt want people to be able to delete data without confirming their identity first.
    So it should really be a form that triggers an email with a unsubscribe link in it to the entered adress.
    Maybe the subscription form can be customised to do this?

    By the way I very much like the newsletter plugin for it’s easy way to customize the newsletter layout.
    Thank you so much for your work Stefano.

    Edda

    #20082
    Lissy01
    Participant

    I have the same Problem.
    My customer is using the Newsletter Plugin only for collecting Emails with Double Opt in.
    She is exporting the news and writing them in an extern tool.
    But how to unscubscribe without an Unsubscribe Form?
    In the old CMS there was a form to put in the email adress for unsubscribe also with a confirmation step via email.
    Is there any solution?

    #20400
    Stefano
    Keymaster

    There is not an unsubscribe form. If she’s sending the email with another software she should find a way to offer a direct cancellation from the email she’s sending, eventually collect cancellations and import those in Newsletter.

    #20675
    Danielxavier
    Participant

    With the standard unsubscribe tag recieved in the confirmation email, it does’ nt link to any unsubscribe form or confirmation? It an empty page with no info. I then tried to make a dedicated page to try an help, but still nothing.
    I made a simple page with [newsletter_profile]. It’s possible to edit you mail, but unsubscribe doesn’t show?

    • This reply was modified 6 years, 6 months ago by Danielxavier.
    #20756
    Stefano
    Keymaster

    There is not an unsubscribe form. For the profile page, if you use the message you can configure on subscription options there you can find an unsubscription link with the profile form.

    #20829
    crystalj
    Participant

    I wanted this functionality as well. I understand that it’s unlikely someone that receives the newsletter with the link will need a page on my site to unsubscribe, but I wanted to offer the functionality anyway (and be able to link to it on my Privacy Policy page). I tried Anonymous’s code, above, with the same result as everyone else. So I worked with it, and came up with a solution that works on my own site (http://www.crystaljag.com). I am posting it as a solution or a starting point for anyone looking for the same, as-is, with no guarantee that it will work for you. I don’t know if the code is as simplified as it could be, or if there is a better way of doing it; it’s very possible that it could be optimized. I don’t know the code language well enough to expertly develop in it, but I made it generic, so you should not have to change anything to make it work for you the same way it works for me (unless you need to change the get_home_url() function to the get_site_url() function to make it reference where your WP files are stored as opposed to your base home site – but I think that the plugin itself uses the home url instead of site, so I don’t think you would have to change that). You may also want to change the wording of the various return messages that are displayed.

    It’s used the same way described by Anonymous: put the code below in your functions.php file, then create an unsubscribe WP page and use the shortcode:

    [newsletter_unsubscribe]

    
    /* Newsletter unsubscribe form */
    add_shortcode('newsletter_unsubscribe','hos_newsletter_unsubscribe');
    function hos_newsletter_unsubscribe($atts) { 
    	global $wpdb;                    
      if (!defined('NEWSLETTER_USERS_TABLE'))
          define('NEWSLETTER_USERS_TABLE', $wpdb->prefix . 'newsletter'); 	
    	extract(shortcode_atts(array(
    		'class'	=> '',
    	), $atts)); 
    	$formcontent = '<script type="text/javascript">
    		//<![CDATA[
    		if (typeof newsletter_check !== "function") {
    			window.newsletter_check = function (f) {
    				var re = "/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/";
    				if (!re.test(f.elements["ne"].value)) {
    					alert("The email is not correct");
    					return false;
    				}
    				for (var i=1; i<20; i++) {
    				if (f.elements["np" + i] && f.elements["np" + i].required && f.elements["np" + i].value == "") {
    					alert("");
    					return false;
    				}
    				}
    				if (f.elements["ny"] && !f.elements["ny"].checked) {
    					alert("You must accept the privacy statement");
    					return false;
    				}
    				return true;
    			}
    		}
    		//]]>;
    		</script>
    		<div class="newsletter newsletter-unsubscription">
    		<form method="post" action="" onsubmit="return newsletter_check(this)" _lpchecked="1">
    		
    		<input type="hidden" name="form_action" value="unsubscribe">
    		<table cellspacing="0" cellpadding="3" border="0">
    		
    		<!-- email -->
    		<tbody><tr>
    			<th>Email</th>
    			<td align="left"><input class="newsletter-email" type="email" name="email_unsub" size="30" required=""></td>
    		</tr>
    		
    		<tr>
    			<td colspan="2" class="newsletter-td-submit">
    				<input class="newsletter-submit" type="submit" value="Unsubscribe">
    			</td>
    		</tr>
    		
    		</tbody></table>
    		</form>
    		</div>';
    	
    	if( "unsubscribe" == $_POST['form_action']) {
        
    		$email = sanitize_email($_POST['email_unsub']);
             
      	// Retrieve the related newsletter user
      	// There is an email matching?   
        $unsub_url = get_unsub_url($email);
        
    		if (empty($unsub_url)) {  
      			$content = '<h1>' . __('Unsubscribe','Newsletter') . '</h1>';
      			$content .= '<p class="red">' . __('That email address was not found.','Newsletter') . '</p>';	
      			$content .= $formcontent;		
        } else {          
          $result = run_url($unsub_url); 
          echo "<p>result: $result</p>";        
      		if( 1 == $result ) {
                              // Unsubscribe Message
      			$content = '<h1>' . __('Successfully Unsubscribed','Newsletter') .'</h1>';
      			$content .= '<p>' . __('You have been successfully unsubscribed from our newsletter.','Newsletter') . '</p>';
      		} else {
      			$content = '<h1>' . __('Unsubscribe Unsuccessful','Newsletter') . '</h1>';
      			$content .= '<p class="red">' . __('The email address was found, but you were not successfully unsubscribed. Please click the unsubscribe link in your most recent newsletter to complete the process.','Newsletter') . '</p>';	
      			$content .= $formcontent;		
      		}
      	}
      } else {
    		$content = '<h1>' . __('Unsubscribe','Newsletter') . '</h1>';
    		$content .= $formcontent;
    	}	  	
    	return $content;     	
    } 
    function get_unsub_url($email) {   
    	global $wpdb;                    
      if (!defined('NEWSLETTER_USERS_TABLE'))
          define('NEWSLETTER_USERS_TABLE', $wpdb->prefix . 'newsletter');
    	// Retrieve the related newsletter user
    	// There is an email matching?   
    
    	$user = $wpdb->query($wpdb->prepare(                  
    			"SELECT * FROM " . NEWSLETTER_USERS_TABLE . " where email=%s limit 1", strtolower($email)
          ));
    	// If not found, create a new Newsletter user, else update the wp_user_id since this email must be linked
    	// to the WP user email.
    	if (empty($user)) {  
    		return null;  
    	} else {
    	  $home_url = get_home_url();
        $url = $wpdb->get_var( $wpdb->prepare(  
    			"SELECT concat('$home_url/?na=uc&nk=',id,'-',token) FROM " . NEWSLETTER_USERS_TABLE . " where email=%s limit 1", strtolower($email) 
        ));
        echo "<p>url: $url</p";
        return $url;   
      }
    }       
    function run_url($url) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_VERBOSE, 0);   
      curl_setopt($ch, CURLOPT_TIMEOUT, 10);     
      $data = curl_exec($ch);
      curl_close($ch);  
      return $data;
    }
    
    #20878
    Guido.
    Participant

    Much better to use one dedicated-page that you not use in your website for the normal visitors and use the ‘profile page’ section to fill that page with some text and {profile_form} <a href="{unsubscription_confirm_url}">unsubscribe</a> in it. That way your readers can also follow the edit subscription for the unsubscribe. This way they don’t unsubscribe for all your newsletters when they only want to unsubscribe for one (am using preference for different newsletters).

    #20915
    crystalj
    Participant

    I posted working code for this functionality the a couple days ago, and the header of this rgread reflected my update, but the post itself still hasn’t shown up? The thread is only displaying 12 of 15 total posts.

Viewing 16 posts - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.