Sailthru_Client::setEmail PHP Method

setEmail() public method

$lists should be an assoc array mapping list name => 1 for subscribed, 0 for unsubscribed
public setEmail ( string $email, array $vars = [], array $lists = [], array $templates = [], integer $verified, string $optout = null, string $send = null, array $send_vars = [] ) : array
$email string
$vars array
$lists array
$templates array
$verified integer 1 or 0
$optout string
$send string
$send_vars array
return array API result
    public function setEmail($email, $vars = [], $lists = [], $templates = [], $verified = 0, $optout = null, $send = null, $send_vars = [])
    {
        $data = ['email' => $email];
        if ($vars) {
            $data['vars'] = $vars;
        }
        if ($lists) {
            $data['lists'] = $lists;
        }
        if ($templates) {
            $data['templates'] = $templates;
        }
        $data['verified'] = (int) $verified;
        if ($optout !== null) {
            $data['optout'] = $optout;
        }
        if ($send !== null) {
            $data['send'] = $send;
        }
        if (!empty($send_vars)) {
            $data['send_vars'] = $send_vars;
        }
        return $this->apiPost('email', $data);
    }

Usage Example

            } else {
                require_once 'client/requires.php';
                $client = new Sailthru_Client(get_option('sailthru_api_key'), get_option('sailthru_secret'));
                $replacement_fields = array();
                if (isset($_POST['fname'])) {
                    $replacement_fields['first_name'] = $_POST['fname'];
                }
                if (isset($_POST['lname'])) {
                    $replacement_fields['last_name'] = $_POST['lname'];
                }
                $all_lists = $form->get_all_lists();
                $lists = array();
                if ($has_lists) {
                    foreach ($all_lists as $id => $list_name) {
                        if (in_array($id, $_POST['lists'])) {
                            $lists[$list_name] = '1';
                        }
                    }
                }
                $client->setEmail($_POST['email'], $replacement_fields, $lists);
                if ((bool) get_option('sailthru_welcome') && ($template = get_option('sailthru_welcome_template'))) {
                    require_once 'client/requires.php';
                    $client = new Sailthru_Client(get_option('sailthru_api_key'), get_option('sailthru_secret'));
                    $r = $client->send($template, $_POST['email'], $replacement_fields, array());
                }
                echo '{}';
            }
        }
        break;
}
die;