在外部PHP文件中使用prestashop Mail :: Send

时间:2017-03-10 13:25:50

标签: php rest prestashop-1.6

我试图在外部php文件中使用Prestashop Mail :: Send(我们的API端点) 我试过包括config.inc.php,init.php也。它看起来像API使用PHP邮件功能。但presta有Mail类,其他Prestashop类正常工作。 我有Prestashop 1.6.1.9和PHP 5.6

我有代码:

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);

}
}

但是我收到了错误:

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/

其他Prestashop类正常工作。 (Configuration :: get,Product :: getPriceStatic)

1 个答案:

答案 0 :(得分:0)

尝试将此方法称为非静态。

如果您使用PHP 5.4+,请尝试使用此代码:

return (new Mail)->Send($id_land, $template_name, $title, $templateVars, $email, "", $from, $fromName);

或者如果你有PHP< 5.4,试试这个:

$mail = new Mail();
return $mail->Send($id_land, $template_name, $title, $templateVars, $email, "", $from, $fromName);