×

info

Dear guests,
You are currently on the old forum we kept as a knowledge base. You will find the new community forum here
Welcome, Guest
Username: Password: Remember me
Keyword

TOPIC: Where to place and how to run AcyMailing PHP API scripts ?

Where to place and how to run AcyMailing PHP API scripts ? 3 years 8 months ago #105424

  • Anonymous user
  • Afrikao's Avatar
  • Posts: 5
  • Karma: 0
Hello to Acyba Community !
My environment - CentOS 7, PHP 7, Joomla 3.6.4, latest AcyMailing Starter.
I've tried to use www.acyba.com/acymailing/64-acymailing-d...html#sendsingleemail
Let's say file name is singlemail.php
<?php

define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
 
if (file_exists(dirname(__FILE__) . '/defines.php')) {
 include_once dirname(__FILE__) . '/defines.php';
}
 
if (!defined('_JDEFINES')) {
 define('JPATH_BASE', dirname(__FILE__));
 require_once JPATH_BASE.'/includes/defines.php';
}
 
require_once JPATH_BASE.'/includes/framework.php';
$app = JFactory::getApplication('site');


if(!include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_acymailing'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php')){
 echo 'This code can not work without the AcyMailing Component';
 return false;
 }
$mailer = acymailing_get('helper.mailer');
$mailer->report = true;
$mailer->trackEmail = true;
$mailer->autoAddUser = false;
$mailer->sendOne(11,'1test@example.com');

?>

Seems the code is OK and it should work.

But the question is - where to place this PHP script under Joomla and how to run ?
I tried something like example.com/customscripts/singlemail.php - seems it does not work.

Second question - is it possible to run such a script from the shell ?
I mean
/usr/bin/php -q /var/www/html/example.com/administrator/components/com_acymailing/helpers/singlemail.php
?

Thanks in advance for some basic hints regarding your API scripts !
Best regards,
Serge
Please log in to post a reply

Where to place and how to run AcyMailing PHP API scripts ? 3 years 8 months ago #105462

  • Alexandre
  • Alexandre's Avatar
  • Posts: 2462
  • Karma: 67
Hi,

Could you please let me know what do you want to do with this script ?
In order to run the script you will have to be able to call it via your browser or insert it into a page which is loaded by your browser.
Please log in to post a reply

Where to place and how to run AcyMailing PHP API scripts ? 3 years 8 months ago #105507

  • Anonymous user
  • Afrikao's Avatar
  • Posts: 5
  • Karma: 0
Hello Alexander,
As per API examples described in the link above and another example from
www.acyba.com/forum/5-acymailing-how-to/...hp-script.html#94777

I want to send a newsletter with ID 11 to a single email
$mailer->sendOne(11,'1test@example.com');
This is from code above - file singlemail.php
example.com - where Joomla is installed.

I got you opinion I can't run this PHP from shell - I have to use a browser.
But where to place this PHP file under Joomla ?
In the root of Joomla ? Under a custom directory ? Somewhere else ?

I made custom directory /scripts/ under Joomla installation, set all permissions to 777
But when I apply through a browser to
/example.com/scripts/singlemail.php
no any email sent.

More than that I see in Apache error logs
PHP Fatal error: require_once(): Failed opening required '/var/www/html/example.com/scripts/includes/defines.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/example.com/scripts/singlemail.php on line 12
Line 12 contains
require_once JPATH_BASE.'/includes/defines.php';

What's wrong with this line ? The code is exactly taken from AcyMailing API - please, see the code above.
Could it be a problem because of PHP 7 ? I don't think so because Joomla itself works without any problem.

When I placed the same file singlemail.php under the root of Joomla and call via browser
/example.com/singlemail.php
it seems the Apache error has disappeared...but anyway no newsletter sent to a single email.

So where is a right place for this API script under Joomla - and how to solve the issue to send a newsletter to a single email ?
Waiting for your comments/hints with great interest.
Last Edit: 3 years 8 months ago by Anonymous user. Reason: additional info
Please log in to post a reply

Where to place and how to run AcyMailing PHP API scripts ? 3 years 8 months ago #105525

  • Alexandre
  • Alexandre's Avatar
  • Posts: 2462
  • Karma: 67
Hi,

A solution could be to insert the file in /administrator/components/com_acymailing/controller and define it as api.php.
Then you will be able to use via this URL :
http://yourwebsite/administrator/index.php?option=com_acymailing&ctrl=api
Please log in to post a reply

Where to place and how to run AcyMailing PHP API scripts ? 3 years 8 months ago #105535

  • Anonymous user
  • Afrikao's Avatar
  • Posts: 5
  • Karma: 0
Hello Alexander,

thank you for the hint, but it does not work.
When under Admin Backend I call
/yourwebsite/administrator/index.php?option=com_acymailing&ctrl=api
(where api = api.php with the exact code as above)
I have a Joomla message
Class 'ApiController' not found

Although when I try, for example, another file from the list of controllers
/yourwebsite/administrator/index.php?option=com_acymailing&ctrl=chooselist
it works.

So it means the code above is wrong although exactly the same code was used in
www.acyba.com/forum/5-acymailing-how-to/...hp-script.html#94777
Strange issue.

But much more important question - is it possible to call api.php NOT FROM /administrator/* ?
Let's imagine I do not worry about safety at all.
Can I call something like
/yourwebsite/index.php?option=com_acymailing&ctrl=api.php
or any other similar way ?

Please, look again - is this code correct ?
<?php

define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
 
if (file_exists(dirname(__FILE__) . '/defines.php')) {
 include_once dirname(__FILE__) . '/defines.php';
}
 
if (!defined('_JDEFINES')) {
 define('JPATH_BASE', dirname(__FILE__));
 require_once JPATH_BASE.'/includes/defines.php';
}
 
require_once JPATH_BASE.'/includes/framework.php';
$app = JFactory::getApplication('site');


if(!include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_acymailing'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php')){
 echo 'This code can not work without the AcyMailing Component';
 return false;
 }
$mailer = acymailing_get('helper.mailer');
$mailer->report = true;
$mailer->trackEmail = true;
$mailer->autoAddUser = false;
$mailer->sendOne(11,'1test@example.com');

?>

If yes - still the same question how to run such PHP script ?
Last Edit: 3 years 8 months ago by Anonymous user.
Please log in to post a reply

Where to place and how to run AcyMailing PHP API scripts ? 3 years 8 months ago #105545

  • Alexandre
  • Alexandre's Avatar
  • Posts: 2462
  • Karma: 67
Hi,

Could you please let me know why don't you use the AcyMailing interfaces in order to send your emails?
Then feel free to put your script in your root folder / (you tried to add it into the /script/ folder last time, so that's why you got an error)
This should do the work.
Please log in to post a reply

Where to place and how to run AcyMailing PHP API scripts ? 3 years 8 months ago #105553

  • Anonymous user
  • Afrikao's Avatar
  • Posts: 5
  • Karma: 0
Hi,
because I'm system administrator and I need to write my own shell script for certain purposes - to use AcyMailing from shell, not from interface.
Thank you.
Please log in to post a reply
Time to create page: 0.058 seconds
Powered by Kunena Forum