You’re most likely getting a 500 because the parameters are not passed correctly.
Try creating a test list and doing an actual send to that list.
Here are three things to try:
1. Make sure all parameters are passed.
As Cameron noted, you have a parameter in the processing page which is not getting passed, and this is most likely the source of the problem:
RequestParameter("Subaction")
To make it work, you need to include the parameter in the link in your first page:
%%=CloudPagesURL(254,"Subaction","unsub")=%%
Above is just hardcoded, so if they have a choice of subscribing/unsubscribing, pass the real parameter.
If they only have a choice to unsubscribe, I would strip this completely from the processing page:
/* Log Unsub Event */
IF RequestParameter("Subaction") == 'unsub' THEN
/* Update ET unsub and log it for tracking */
And strip the ENDIF
at the end.
2. If you’re using the CloudPagesURL function, you don’t need to pass the personalization strings separately.
Change to the following in your processing page:
SET @SfContactId = RequestParameter("_subscriberkey")
SET @EmailAddress = RequestParameter("emailaddr")
You can try displaying the values on the page to see if they are passed correctly:
@SfContactId: %%=v(@SfContactId)=%% <br>
@EmailAddress: %%=v(@EmailAddress)=%%
3. Debug the Salesforce functions.
One last thing you can do is wrapping your script in a try/catch statement, to see if the Salesforce functions are causing any issues.
Best Answer
The SFMC-hosted custom preferences centers that I've built are landing/microsite pages coded in SFMCs Server-Side JavaScript (SSJS).
You can accomplish nearly all of what you need for subscription/preference center interactions using SSJS.
Here's a simple boilerplate that I use:
https://gist.github.com/wvpv/19777e1167d6ac91e2e8
SSJS Reference:
You can also code your pages in AMPScript, which is faster, but more verbose. There are also no arrays in AMPScript.