Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 邮件:使用自定义模块和电子邮件模板发送_Php_Prestashop 1.6 - Fatal编程技术网

Php 邮件:使用自定义模块和电子邮件模板发送

Php 邮件:使用自定义模块和电子邮件模板发送,php,prestashop-1.6,Php,Prestashop 1.6,我目前正在创建一个模块,用于在hookActionProductCancel上执行一组代码。模块运行良好,我想在执行后发送一封电子邮件 $template_path = $this->local_path . 'mails/'; Mail::Send((int)(Configuration::get('PS_LANG_DEFAULT')), 'xxx', //need to change the template directory to point to custom module

我目前正在创建一个模块,用于在hookActionProductCancel上执行一组代码。模块运行良好,我想在执行后发送一封电子邮件

$template_path = $this->local_path . 'mails/';

Mail::Send((int)(Configuration::get('PS_LANG_DEFAULT')),
 'xxx', //need to change the template directory to point to custom module
 'Subject',
 array(
   '{aaa}' => $bbb,
   '{bbb}' => $ccc,
   '{ccc}' => $ddd,
   '{ddd}' => $eee
 ),
 $to,
 null, null, null);
我已经创建了模板,并按如下方式放置文件:

  • ../mails/en/xxx.html
  • ../mails/en/xxx.txt
  • 虽然我知道上面是电子邮件模板的默认导航,但如何使用放置在自定义模块目录中的模板

    我已经创建了一个目录-../modules/custommodule/mails/,并放置了这两个文件,但没有成功地指向它


    感谢您的指导。谢谢。

    您可以在中指定模板路径

    您可以看到第11个参数是
    $template\u path
    ,所以您只需要指定它(如果您从主模块类调用send方法,您可以使用
    $this->local\u path.'mails/'
    )。
    $template\u path
    参数必须是服务器文件路径而不是URI,因为该方法使用
    file\u exists()
    检查模板是否存在。方法将从您的模块路径中提取它实际上是一个自定义模块模板

    现在,该方法将首先检查中是否有邮件模板

    themes/shop\u theme/modules/mymodule/mails/iso\u lang/xxx.html

    然后在

    modules/mymodule/mails/iso_lang/xxx.html

    并加载找到的第一个模板。txt文件也是如此

    编辑:

    如何正确执行方法:

    Mail::Send(
        (int)(Configuration::get('PS_LANG_DEFAULT')),
        'xxx', //need to change the template directory to point to custom module
        'Subject',
        array(
           '{aaa}' => $bbb,
           '{bbb}' => $ccc,
           '{ccc}' => $ddd,
           '{ddd}' => $eee
        ),
        $to,
        null, 
        null, 
        null,
        null,
        null,
        $this->local_path . 'mails/' // 11th parameter is template path
    )
    

    可以在中指定模板路径

    您可以看到第11个参数是
    $template\u path
    ,所以您只需要指定它(如果您从主模块类调用send方法,您可以使用
    $this->local\u path.'mails/'
    )。
    $template\u path
    参数必须是服务器文件路径而不是URI,因为该方法使用
    file\u exists()
    检查模板是否存在。方法将从您的模块路径中提取它实际上是一个自定义模块模板

    现在,该方法将首先检查中是否有邮件模板

    themes/shop\u theme/modules/mymodule/mails/iso\u lang/xxx.html

    然后在

    modules/mymodule/mails/iso_lang/xxx.html

    并加载找到的第一个模板。txt文件也是如此

    编辑:

    如何正确执行方法:

    Mail::Send(
        (int)(Configuration::get('PS_LANG_DEFAULT')),
        'xxx', //need to change the template directory to point to custom module
        'Subject',
        array(
           '{aaa}' => $bbb,
           '{bbb}' => $ccc,
           '{ccc}' => $ddd,
           '{ddd}' => $eee
        ),
        $to,
        null, 
        null, 
        null,
        null,
        null,
        $this->local_path . 'mails/' // 11th parameter is template path
    )
    

    是的,我同意'DredRot'必须正确地传递第11个参数,并且若遇到错误

    $this->local\u路径邮件/'

    比尝试

    $this->module->getLocalPath().'mails/'
    

    是的,我同意'DredRot'必须正确地传递第11个参数,并且若遇到错误

    $this->local\u路径邮件/'

    比尝试

    $this->module->getLocalPath().'mails/'
    

    我尝试了$template_path='../modules/custommodule/mails/';但它仍然返回错误-缺少以下电子邮件模板:/var/www/domain/public\u html/mails/en/xxx.txt。。。。我错过什么了吗?它仍然指向原始路径。您是否使用
    $this->local\u path尝试过该路径邮件/'
    ?是的,我。。。我试过了,但它返回了相同的错误,所以我尝试了另一种方法。似乎它仍然指向邮件/en…我是否需要更改Mail:Send中与模板有关的任何内容?能否更新您的问题,说明您如何调用
    Mail::Send()
    ?我在我的开发实例中进行了测试,它运行得很好。我尝试了$template_path='../modules/custommodule/mails/';但它仍然返回错误-缺少以下电子邮件模板:/var/www/domain/public\u html/mails/en/xxx.txt。。。。我错过什么了吗?它仍然指向原始路径。您是否使用
    $this->local\u path尝试过该路径邮件/'
    ?是的,我。。。我试过了,但它返回了相同的错误,所以我尝试了另一种方法。似乎它仍然指向邮件/en…我是否需要更改Mail:Send中与模板有关的任何内容?能否更新您的问题,说明您如何调用
    Mail::Send()
    ?我在我的dev实例中进行了测试,结果很好。谢谢。德雷特的建议现在一切都好了。谢谢。德雷特的建议现在一切都好了。