doufei8691 2017-03-10 13:25 采纳率: 100%
浏览 36

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

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)

  • 写回答

1条回答 默认 最新

  • doujianmin6527 2017-03-10 13:36
    关注

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

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c