Bitrix Site Manager

CSubcription::Add

CSubcription::Add(
    $arFields, 
    $SITE_ID=SITE_ID
);

The method Add adds a subscription and sends the message containing the subscription confirmation code to the subscriber unless he has chosen not to receive such messages.

Parameters

ParameterDescription
$arFields Associated array containing the keys and values of Subscription object fields. The following fields can also be used:
  • RUB_ID - array of ID's of the subscriptions to which a user subscribes;
  • SEND_CONFIRM - specifies to send the message containing the confirmation code to the subscriber (Y/N).
$SITE_ID The ID of the site used to determine the template of the subscription confirmation message. The parameter has the default value of the current site ID. 

Return Values

Returns the subscription ID on success. In case of an error, it returns false and the class variable LAST_ERROR contains the error description.

Example



//there must be at least one newsletter category
if(!is_array($RUB_ID) || count($RUB_ID) == 0)
    $strWarning .= "There must be at least one category."."<br>";

if($strWarning == "")
{
    $arFields = Array(
        "USER_ID" => ($USER->IsAuthorized()? $USER->GetID():false), 
        "FORMAT" => ($FORMAT <> "html"? "text":"html"), 
        "EMAIL" => $EMAIL, 
        "ACTIVE" => "Y",
        "RUB_ID" => $RUB_ID
    );

    //can add without authorization
    $ID = $subscr->Add($arFields);
    if($ID>0)
        CSubscription::Authorize($ID);
    else
        $strWarning .= "Error adding subscription: ".$subscr->LAST_ERROR."<br>";
}