vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Mailchimp plugin for 3.8.7: What do I need to modify? (https://vborg.vbsupport.ru/showthread.php?t=263555)

jGas 05-13-2011 08:01 AM

Mailchimp plugin for 3.8.7: What do I need to modify?
 
Hi, this code is working great on the site where I found it, http://www.bestrecipes.com.au/site/mailchimp.html, that is running 3.8.3 but not on my board that is 3.8.7.

This is the plugin code:



Code:

require_once 'mailchimp/MCAPI.class.php'; // location of API file, relative to
forum root directory
$apikey= 'myapikey-us2'; // your API key
$listId = '3af3706004321'; // the list ID

// Connect to the MailChimp server
$api = new MCAPI($apikey);

if ($api->errorCode!=''){

// an error occurred while logging in, errors commented in HTML
echo "<!-- code:".$api->errorCode."-->";
echo "<!-- msg :".$api->errorMessage."-->";
die();
}

// get current user details
$my_email=($vbulletin->userinfo['email']);

// profile fields are best set up as single-selection radio buttons,
// use multiple profile fields for interest groups and mail format

// vBulletin profile field options:
// use Yes/No options (use HTML/Text for mail format)
// Set default: Yes
// Field Required: No but display at registration
// Field Editable by User: Only at registration
// Handle unsubscribes and profile updating via links in mailings, or another
API plugin

$news1=($vbulletin->userinfo['field12']); // add custom profile field number
for interest group 1
// $news2=($vbulletin->userinfo['field14']); // add custom profile field
number for interest group 2
// $news3=($vbulletin->userinfo['field15']); // add custom profile field
number for interest group 3

$newsformat=strtolower(($vbulletin->userinfo['field13'])); // profile field
number for mail format, html or text

// add interest group names, note trailing commas in all but last one - a
quick hack but it works!

if ($news1=='Yes') {
$interests='Interest group name here,';  // escape apostrophes in name with a
backslash i.e. What\'s On
}

if ($news2=='Yes') {
$interests.='Interest group name here,';
}

if ($news3=='Yes') {
$interests.='Interest group name here';
}

$merge_vars = array('INTERESTS'=>$interests);
// only send request if subscribed to at least 1 newsletter
if ($news1=='Yes' || $news2=='Yes' || $news3=='Yes') {
$retval = $api->listSubscribe( $listId, $my_email, $merge_vars, $newsformat
);
}

if (!$retval){
        // return error codes, commented in HTML
echo "<!--Newsletter failed!-->";
echo "<!--\tCode=".$api->errorCode."-->";
echo "<!--\tMsg=".$api->errorMessage."-->";
// email backup for API failures, multiple subscribes etc.
$to      = 'info@musicadigitale.net';
$subject = 'Newsletter API failed';
$message = "The following member details were not subscribed by the API:\n";
$message .= "Email: $my_email\n";
$message .= "Interest groups: $interests\n";
$message .= "Mail format: $newsformat\n";
$message .= "Error message: " . $api->errorMessage . "";
$headers = "From: MailChimp API <adminemail@domain.com>\n";
$headers .= "Reply-To: adminemail@domain.com\n";
$headers .= "X-Mailer: Your forum name\n";
mail($to, $subject, $message, $headers);
} else {
    echo "<!--Newsletter subscribed ok-->";
}

Many thanks for your time :D

kh99 05-13-2011 01:32 PM

In the line:

Code:

$news1=($vbulletin->userinfo['field12']);

Did you change the field to match your actual custom profile field number?

Also if those are really your api key and list number I'm guessing you shouldn't be posting them (and if they aren't, did you enter your values there when you tried it?).

You didn't say what actually happens on your site.

jGas 05-13-2011 02:15 PM

Thanks for your reply! ;)
Don't worry, I removed the correct keys and list number before posting here ;)
Also the fields are correct.

This plugin works during registration of a new user.
When I try to register, the user is correctly registered but
1) it's not added to the mailing list
2) I get a white page instead of "you need to confirm your account, check your email" page...
That's strange!

kh99 05-13-2011 02:33 PM

Sorry, but occasionally someone will copy a block of code and have no idea about how it shoud be edited :)

Anyway, I'm probably going to say a couple more obvious things, but: if you see a white page I'd guess that maybe it's hitting that die(). Did you "view source" of the blank page to see if those html comments are there?

Also maybe make sure that the MCAPI.class.php file is in the right place, but I think you'd see an error message if is wasn't.

jGas 05-13-2011 03:05 PM

No problem :)
Well I can't view the source because it isn't a real blank page, it's a "Content Encoding Error" page (firefox reports this error)

MCAPI.class.php file is in the right place :)

kh99 05-13-2011 03:15 PM

Hmm...maybe you could comment out the die and put the code after that block in an else and see what that does.

jGas 05-13-2011 03:25 PM

If I comment the "die" I get the same message as before... maybe because it isn't an api error...?

kh99 05-13-2011 03:28 PM

Yeah, looks like my guess was wrong. :(

jGas 05-13-2011 03:36 PM

The problem is, that on a vbulletin 3.8.3 it IS working...


All times are GMT. The time now is 05:38 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00981 seconds
  • Memory Usage 1,731KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete