将更多参数传递给$ merge_vars数组

时间:2014-12-17 13:38:25

标签: php mailchimp

我想使用php将个人信息保存到Mailchimp,但我无法使其正常工作,因为我将许多参数传递给数组。

我的列表需要以下所有字段:

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='si@gmail.com';
$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'; 
}

3 个答案:

答案 0 :(得分:0)

可能你的listSubscribe方法没有包含3个参数的签名,所以你必须只传递accept参数,你可以在$api类中查看哪个。

答案 1 :(得分:0)

这是来自MAPI.class sources的函数listSubscribe的签名:

/**
     * 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)吗?

答案 2 :(得分:0)

解决: - )

问题是我传递错误的手机号码格式“074-524-2520”,它应该是这种格式“0745242520”。