Select the newsletter you would like to subscribe to:
"; } else { // the subscription was complete print "Thank you. You will receive an email asking you to confirm your subscription.
"; } ?>'Public Pages', 'is_hidden' => 0, 'is_active' => 1, 'api_key' => $mail_subscription_user_key, )); if (!empty($group_query['is_error'])) { civiproxy_http_error($group_query['error_message'], 500); } else { $groups = $group_query['values']; if (empty($groups)) { civiproxy_http_error("No newsletter groups found!", 500); } } // VERIFY / CHECK PARAMETERS $parameter_errors = array(); if (!empty($_REQUEST['email'])) { // get parameters $email = $_REQUEST['email']; if (!preg_match("#^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$#i", $email)) civiproxy_http_error("'$email' is not a valid email address.", 500); if (empty($_REQUEST['group_id'])) civiproxy_http_error("No newsletter group selected!", 500); $group_id = $_REQUEST['group_id']; // ALL FINE. SUBSCRIBE USER! // first, get/create the contact $contact_query = civicrm_api3('Contact', 'create', array( 'email' => $email, 'contact_type' => 'Individual', 'dupe_check' => 1, 'api_key' => $mail_subscription_user_key, )); if (!empty($contact_query['is_error'])) { // an error occured during contact generation/identification if ($contact_query['error_code'] == 'duplicate') { // there have been multiple duplicates found $contact_id = $contact_query['ids'][0]; } else { civiproxy_http_error($contact_query['error_message'], 500); } } else { $contact_id = $contact_query['id']; } // then: subscribe $subscribe_query = civicrm_api3('MailingEventSubscribe', 'create', array( 'email' => $email, 'contact_id' => $contact_id, 'group_id' => $group_id, 'api_key' => $mail_subscription_user_key, )); if (!empty($subscribe_query['is_error'])) { // an error occured during the actual subscription civiproxy_http_error($subscribe_query['error_message'], 500); } } ?>