acymailing

aje

Member
Is there a way to sign up on a list in acymail from a form silent ?` When i use redirect i get the message from acymail but i want to show an own page.
 
I don't think there is one. You are redirecting to ACY's page, at which point you are outside our control.

The only relatively quick solution I could think of would be to do it through a CURL call in a PHP submission script. So instead of redirecting the browser with the subscribe query string, run that as a CURL request on the server side, then redirect the browser to your own page.

So you could run the plugin onAfterProcess, something like this:

PHP:
$myEmail = '{yourtable___youremail}';
if (!empty($myEmail)) {
   $url = COM_FABRIK_LIVESITE . "index.php?option=com_acymailing&ctrl=sub&task=optin&hiddenlists=2&user[email]=" . $myEmail;
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_HEADER, 1);
   curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
   curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
   $data = curl_exec($ch);
   curl_close($ch);
}

You may need to use just the short element name, like {youremail}, when running onAfterProcess.

And change your redirect to point to your own landing page.

You could also check the content of $data to work out if the subscription worked or not, and provide your own feedback.

-- hugh
 
Actually, looking at ACY's API, it wouldn't be too hard to use that instead of doing a CURL ...

PHP:
$myEmail = '{yourtable___youremail}';
if (!empty($myEmail)) {
   if (! include_once JPATH_ADMINISTRATOR . '/components/com_acymailing/helpers/helper.php')
   {
      throw new RuntimeException("Acymailing not installed");
      return false;
    }

   $myUser = new stdClass();
   $myUser->email = $myEmail;
   //If you require a confirmation but don't want the user to have to confirm his subscription via the API, you can set the confirmed field to 1:
   //$myUser->confirmed = 1;
   $subscriberClass = acymailing_get('class.subscriber');
   $subid = $subscriberClass->save($myUser);

   $newSubscription = array();
   $newList = array();
   $newList['status'] = 1;
   $newSubscription[2] = $newList; // Replace 2 with the ID of the list.

   $subscriberClass->saveSubscription($subid,$newSubscription);
}


I haven't tested this, so it may not work first time, but it shouldn't take much tweaking to make it work.

-- hugh
 
Last edited:
Hi
Tried this and the user gets add but not the name. Another thing is that he isnt added to any list. I have replaced the 2 with 11 wich is the id on my list.
 
Hello. Have been really busy, but now i have gotten the code to work. I still dont get the name into acymail. Have a element field which is called name. this i need to get into the acymail as the name field. Is this possible ?
 
Hello, at a guess it would be:

PHP:
$myEmail = '{yourtable___youremail}';
$myName = '{yourtable___yourname}';

if (!empty($myEmail)) {
   if (! include_once JPATH_ADMINISTRATOR . '/components/com_acymailing/helpers/helper.php')
   {
      throw new RuntimeException("Acymailing not installed");
      return false;
    }

   $myUser = new stdClass();
   $myUser->email = $myEmail; 
   $myUser->name = $myName;

   //If you require a confirmation but don't want the user to have to confirm his subscription via the API, you can set the confirmed field to 1:
   //$myUser->confirmed = 1;
   $subscriberClass = acymailing_get('class.subscriber');
   $subid = $subscriberClass->save($myUser);

   $newSubscription = array();
   $newList = array();
   $newList['status'] = 1;
   $newSubscription[2] = $newList; // Replace 2 with the ID of the list.

   $subscriberClass->saveSubscription($subid,$newSubscription);
}
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top