ActiveCampaign API script: Add a subscriber and trigger instant autoresponders to send.
- Our PHP API library
- jQuery (it's loaded in the script if you don't use it already)
- Familiarity working with PHP code
You can install example-add_subscriber_send_instant by downloading (or cloning) the source.
Input your ActiveCampaign URL and API key at the top of the script. Example below:
define("ACTIVECAMPAIGN_URL", "https://youraccount.activehosted.com"); define("ACTIVECAMPAIGN_API_KEY", "8yhuih...768fd56et67");
Make sure the path to the PHP library is correct:
require_once("../../activecampaign-api-php/includes/ActiveCampaign.class.php");
Enter your list ID (which new subscribers will be added to):
$listid = 1;
By default the form looks very basic (to keep it simple):
If you want to include a first and last name in the form, feel free to add new fields. Then in the PHP code, make sure to comment out the default values:
// these values should come across from the form (make sure to name them the same as below) //$_POST["first_name"] = ""; //$_POST["last_name"] = "";
Optional: If your autoresponder relies on a segment that looks at a custom field value, include any custom field values in the $_POST
array:
$_POST["field"] = array("%PERS_1%,0" => "Custom field value");
The custom field value could be part of the HTML form, or hard-coded in your script (where subscribers don't see it).
If you are using Ajax to submit the form, update the URL in the jQuery section:
geturl = $j.ajax({ url: '', // the URL to this page.
If you don't use Ajax, update the HTML form element to include the URL:
<form id="subscribe_form" method="post" action="URL TO THIS PAGE">
We'd love to help if you have questions or problems. Report issues using the Github Issue Tracker or email help@activecampaign.com.