Use prestashop Mail::Send in external PHP file - php

i trying to use Prestashop Mail::Send in external php file (Our API endpoint)
I tryied include config.inc.php, init.php also. It looks like API working with PHP mail functions. But presta have Mail class, other Prestashop classes works correctly.
I have Prestashop 1.6.1.9 and PHP 5.6
I have code:
class VoucherModel extends baseModel{
// Other methods
public function addSubscriber($email)
{
$result = Db::getInstance()->insert("mail_subscribers", array(
"email" => pSQL($email)
));
if($result){
$cartRule = "XYZ123";
$sendMail = $this->_sendMail($email, $cartRule);
return $sendMail;
}
}
public function _sendMail($email, $code = "LOVEMANA")
{
$templateVars['{code}'] = $code;
$id_land = Language::getIdByIso('cs');
$template_name = 'sendvoucher';
$title = 'Váše kredity';
$from = Configuration::get('PS_SHOP_EMAIL');
$fromName = Configuration::get('PS_SHOP_NAME');
$mailDir = _PS_THEME_DIR_.'/mails/';
return Mail::Send($id_land, $template_name, $title, $templateVars, $email, "", $from, $fromName);
}
}
But i getting error:
Got error 'PHP message: PHP Deprecated: Non-static method Mail::send() should not be called statically, assuming $this from incompatible context in /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/models/prestashop.php on line 780
PHP message: PHP Stack trace:
PHP message: PHP 1. {main}() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/index.php:0
PHP message: PHP 2. Luracast\\Restler\\Restler->handle() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/index.php:41
PHP message: PHP 3. Luracast\\Restler\\Restler->call() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/include/Luracast/Restler/Restler.php:283
PHP message: PHP 4. call_user_func_array:{/home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/include/Luracast/Restler/Restler.php:989}() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/include/Luracast/Restler/Restler.php:989
PHP message: PHP 5. v1\\Api->subscribe() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/include/Luracast/Restler/Restler.php:989
PHP message: PHP 6. prestashop->addSubscriber() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/v1/Api.php:1090
PHP message: PHP 7. prestashop->_sendMail() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/models/prestashop.php:764
PHP message: PHP Deprecated: Non-static method PEAR::raiseError() should not be called statically, assuming $this from incompatible context in /usr/share/php/Mail.php on line 117
PHP message: PHP Stack trace:
PHP message: PHP 1. {main}() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/index.php:0
PHP message: PHP 2. Luracast\\Restler\\Restler->handle() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/index.php:41
PHP message: PHP 3. Luracast\\Restler\\Restler->call() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/include/Luracast/Restler/Restler.php:283
PHP message: PHP 4. call_user_func_array:{/home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/include/Luracast/Restler/Restler.php:989}() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/include/Luracast/Restler/Restler.php:989
PHP message: PHP 5. v1\\Api->subscribe() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/include/Luracast/Restler/Restler.php:989
PHP message: PHP 6. prestashop->addSubscriber() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/v1/Api.php:1090
PHP message: PHP 7. prestashop->_sendMail() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/models/prestashop.php:764
PHP message: PHP 8. Mail->send() /home/97569-75425.cloudwaysapps.com/axbxzqwhfd/public_html/obchod/mobileapiv2/models/prestashop.php:780
', referer: https://beta.drink-mana.com/en/
Other Prestashop classes work correctly. (Configuration::get, Product::getPriceStatic)

Try to call this method non-statical.
If you have PHP 5.4+ try to use this code:
return (new Mail)->Send($id_land, $template_name, $title, $templateVars, $email, "", $from, $fromName);
Or if u have PHP < 5.4, try this:
$mail = new Mail();
return $mail->Send($id_land, $template_name, $title, $templateVars, $email, "", $from, $fromName);

Related

issues running php as it unable to find the file

I am using the following to run the php file under xampp htdocs with foldername as kraken but i am getting an error
<?php
require_once 'KrakenAPIClient.php';
$key = 'dfdfdfdf';
$secret = 'dfdfdfdf';
// set which platform to use (currently only beta is operational, live available soon)
$beta = false;
$url = $beta ? 'https://api.beta.kraken.com' : 'https://api.kraken.com';
$sslverify = $beta ? false : true;
$version = 0;
$kraken = new KrakenAPI($key, $secret, $url, $version, $sslverify);
error i am getting is:
Fatal error: Uncaught Error: Class 'KrakenAPI' not found in C:\xampp\htdocs\kraken\example.php:21 Stack trace: #0 {main} thrown in C:\xampp\htdocs\kraken\example.php on line 21
You'd need to alias the class with use, before being able to skip it's name-space:
use \Payward\KrakenAPI;
Also see the PHP manual which I've linked for a more detailed explanation.

Call to undefined method Infusionsoft\Api\Rest\ContactService::addWithDupCheck()

This was working all this while with no issues and updates.
$user_id = $infusionsoft->contacts->addWithDupCheck($contact, 'Email');
Now all of a sudden it isn't
PHP Fatal error: Uncaught Error: Call to undefined method
Infusionsoft\Api\Rest\ContactService::addWithDupCheck() in
/home/user/public_html/infusionsoft/addContact.cli.php:29
~/public_html/infusionsoft$ cat composer.json
{
"require": {
"infusionsoft/php-sdk": "^1.0"
}
}
InfusionSoft has replaced their older XML-RPC API with REST. REST is now default. So I had to do :
$user_id = $infusionsoft->contacts('xml')->addWithDupCheck($contact, 'Email');

How to reference a Class Method using an array variable in PHP7?

I've moved from PHP5 to PHP7.
The following code no longer works.
<?php
class sandbox {
function doit() {
$method = array('name' => 'testresponse');
return $this->$method['name']();
}
function testresponse(){
return "Hi!";
}
}
$h = new sandbox();
echo "Hello, " . $h->doit();
I'm wondering what is the new syntax for this?
Here are the PHP errors I'm getting
A PHP Error was encountered Severity: Notice
Severity: Notice
Message: Array to string conversion
Filename: front/sandbox.php
Line Number: 20
And
Fatal error: Uncaught Error: Function name must be a string in /var/www/application/controller/sandbox.php:20 Stack trace: #0
Change this
return $this->$method['name']();
to this
return $this->{$method['name']}();

Symfony 2.7.4 twig error

I have just upgraded to Symfony 2.7.4 from 2.7.3.
After the upgrade a form that worked under 2.7.3 is now throwing this error
An exception has been thrown during the compilation of a template ("Notice: Undefined variable: test")
There is no variable in the template named 'test'.
The exception also shows this code snippet:
if ($function instanceof Twig_SimpleFunction && $function->isDeprecated()) {
$message = sprintf('Twig Function "%s" is deprecated', $function->getName());
if ($test->getAlternative()) {
$message .= sprintf('. Use "%s" instead', $function->getAlternative());
}
$message .= sprintf(' in %s at line %d.', $this->parser->getFilename(), $line);
This snippet suggests that twig is testing for a deprecated function and, if true, Symfony is objecting to an undefined variable $test.
Has anyone experienced this error or can give advise on how to resolve?
Could this error be caused indirectly by something else in the form?
You should upgrade to Twig 1.21.2 see http://symfony.com/blog/twig-1-21-2-released

Got error when running Kohana DB migration

I am using Kohana php framework, when I try to run minion, I got this exception error:
PHP Fatal error: Call to undefined function __() in /system/classes/Kohana/Kohana/Exception.php on line 53
PHP Fatal error: Call to undefined function __() in /system/views/kohana/error.php on line 64
This is the code in Exception.php:
public function __construct($message = "", array $variables = NULL, $code = 0, Exception $previous = NULL)
{
// Set the message
$message = __($message, $variables);
// Pass the message and integer code to the parent
parent::__construct($message, (int) $code, $previous);
// Save the unmodified code
// #link http://bugs.php.net/39615
$this->code = $code;
}
This is the code in error.php
{<?php echo __('PHP internal call') ?>}

Categories