2014-12-17 8 views
0

Я хочу сохранить личную информацию в Mailchimp с помощью php, но я не могу заставить ее работать, потому что я передаю много параметров массиву.

Мой список требует и все следующие поля:

First Name FNAME 
Last Name LNAME 
Email Address* EMAIL 
Password* PASS 
Password Again* PASSAGAIN 
Phone Number* PHONE 
Province Information* PROVINCE 

Я использую MCAPI.class.php библиотеку. Вот мой код:

$listid='b9d1d1f656'; 
$email='[email protected]'; 
$name='Innocent'; // Enter subscriber first name 
$lname='Sho'; // Enter subscriber last name 
$pass = 'Sim#'; 
$passagain = 'Sim#'; 
$phone = '047-807-7320'; 
$province = 'Western Cape'; 

$merge_vars = array('FNAME' => $name, 'LNAME' => $lname, 'EMAIL' => $email, 'PASS' => $pass,  'PASS_AGAIN' => $passagain, 'PHONE' => $phone, 'PROVINCE' => $province); 

if($api->listSubscribe($listid, $email, $merge_vars, $email_type='html', $double_optin=true, $update_existing=false, $replace_interests=false, $send_welcome=false) === true) { 
    echo 'success'; 
}else 
{ 
    echo 'Unsuccessfully'; 
} 
+0

Вы получаете ошибку любого типа? Если так, то, что это? –

+0

Он просто отображает сообщение «Неудачно», но когда я вставляю в список, для которого требуются 3 параметра, например FNAME, LNAME и EMAIL, он работает, но когда я добавляю больше параметров, он не работает. –

+0

Добавьте сообщение об ошибках в начало вашего файла (ов) сразу после открытия '

ответ

0

Возможно ваш метод listSubscribe не имеет подписи с 3 параметрами, так что вы должны пройти только принимают параметры, у вас есть, что посмотреть в $api класс знать, какие.

+0

Можете ли вы добавить метод ListSubscribe более 3-х параметров? –

0

Это подпись функции listSubscribe из MAPI.class sources:

/** 
    * Subscribe the provided email to a list. By default this sends a confirmation email - you will not see new members until the link contained in it is clicked! 
    * 
    * @section List Related 
    * 
    * @example mcapi_listSubscribe.php 
    * @example json_listSubscribe.php   
    * @example xml-rpc_listSubscribe.php 
    * 
    * @param string $id the list id to connect to. Get by calling lists() 
    * @param string $email_address the email address to subscribe 
    * @param array $merge_vars optional merges for the email (FNAME, LNAME, etc.) (see examples below for handling "blank" arrays). Note that a merge field can only hold up to 255 bytes. Also, there are a few "special" keys: 
         string EMAIL set this to change the email address. This is only respected on calls using update_existing or when passed to listUpdateMember() 
         string NEW-EMAIL set this to change the email address. This is only respected on calls using update_existing or when passed to listUpdateMember(). Required to change via listBatchSubscribe() - EMAIL takes precedence on other calls, though either will work. 
         array GROUPINGS Set Interest Groups by Grouping. Each element in this array should be an array containing the "groups" parameter which contains a comma delimited list of Interest Groups to add. Commas in Interest Group names should be escaped with a backslash. ie, "," => "\," and either an "id" or "name" parameter to specify the Grouping - get from listInterestGroupings() 
         string OPTIN_IP Set the Opt-in IP field. <em>Abusing this may cause your account to be suspended.</em> We do validate this and it must not be a private IP address. 
         string OPTIN_TIME Set the Opt-in Time field. <em>Abusing this may cause your account to be suspended.</em> We do validate this and it must be a valid date. Use YYYY-MM-DD HH:ii:ss to be safe. Generally, though, anything strtotime() understands we'll understand - <a href="http://us2.php.net/strtotime" target="_blank">http://us2.php.net/strtotime</a> 
         array MC_LOCATION Set the members geographic location. By default if this merge field exists, we'll update using the optin_ip if it exists. If the array contains LATITUDE and LONGITUDE keys, they will be used. NOTE - this will slow down each subscribe call a bit, especially for lat/lng pairs in sparsely populated areas. Currently our automated background processes can and will overwrite this based on opens and clicks. 

         <strong>Handling Field Data Types</strong> - most fields you can just pass a string and all is well. For some, though, that is not the case... 
         Field values should be formatted as follows: 
         string address For the string version of an Address, the fields should be delimited by <strong>2</strong> spaces. Address 2 can be skipped. The Country should be a 2 character ISO-3166-1 code and will default to your default country if not set 
         array address For the array version of an Address, the requirements for Address 2 and Country are the same as with the string version. Then simply pass us an array with the keys <strong>addr1</strong>, <strong>addr2</strong>, <strong>city</strong>, <strong>state</strong>, <strong>zip</strong>, <strong>country</strong> and appropriate values for each 

         string birthday the month and day of birth, passed as MM/DD 
         array birthday the month and day of birth, passed in an array using the keys <strong>month</strong> and <strong>day</strong> 

         string date use YYYY-MM-DD to be safe. Generally, though, anything strtotime() understands we'll understand - <a href="http://us2.php.net/strtotime" target="_blank">http://us2.php.net/strtotime</a> 
         string dropdown can be a normal string - we <em>will</em> validate that the value is a valid option 
         string image must be a valid, existing url. we <em>will</em> check its existence 
         string multi_choice can be a normal string - we <em>will</em> validate that the value is a valid option 
         double number pass in a valid number - anything else will turn in to zero (0). Note, this will be rounded to 2 decimal places 
         string phone If your account has the US Phone numbers option set, this <em>must</em> be in the form of NPA-NXX-LINE (404-555-1212). If not, we assume an International number and will simply set the field with what ever number is passed in. 
         string website This is a standard string, but we <em>will</em> verify that it looks like a valid URL 
         string zip A U.S. zip code. We'll validate this is a 4 or 5 digit number. 

    * @param string $email_type optional email type preference for the email (html, text, or mobile defaults to html) 
    * @param bool $double_optin optional flag to control whether a double opt-in confirmation message is sent, defaults to true. <em>Abusing this may cause your account to be suspended.</em> 
    * @param bool $update_existing optional flag to control whether existing subscribers should be updated instead of throwing an error, defaults to false 
    * @param bool $replace_interests optional flag to determine whether we replace the interest groups with the groups provided or we add the provided groups to the member's interest groups (optional, defaults to true) 
    * @param bool $send_welcome optional if your double_optin is false and this is true, we will send your lists Welcome Email if this subscribe succeeds - this will *not* fire if we end up updating an existing subscriber. If double_optin is true, this has no effect. defaults to false. 
    * @return boolean true on success, false on failure. When using MCAPI.class.php, the value can be tested and error messages pulled from the MCAPI object (see below) 
    */ 
    function listSubscribe($id, $email_address, $merge_vars=NULL, $email_type='html', $double_optin=true, $update_existing=false, $replace_interests=true, $send_welcome=false) 

Вы уверены, что вы можете передать пустой $id (ваш $listid)?

+0

Да, я передаю свой $ listid –

+0

В вашем примере он пуст (' $ listid = ''; ') ... – MarcoS

+0

Я удалил его, когда я отправлял вопрос, но он там ... –

0

решаемые :-)

Проблема заключалась в том, что я передаю формат неправильный номер мобильного телефона «074-524-2520», он должен быть в этом формате «0745242520».

Смежные вопросы