我正在编写新模块,我想在创建帐户后自动向员工发送邮件。我重写了AdminEmployeesController控制器,但当我调用Mail :: Send()时,这最后一个使用prestashop项目根目录中的mails目录而不是我在模块根目录中创建的目录。
class AdminEmployeesController extends AdminEmployeesControllerCore
{
/**
* Object creation
*/
public function processAdd()
{
if(parent::processAdd()){
$this->sendMail();
}
}
/*
* Send email to the new employer
* */
public function sendMail()
{
Mail::Send(
$this->context->language->id,
'selcreate_account',
Mail::l('Creation de compte'),
array(
'{firstname}' =>Psql(Tools::getValue('firstname')),
'{lastname}' =>Psql(Tools::getValue('lastname')),
'{passwd}' => Psql(Tools::getValue('passwd')),
'{email}' => Psql(Tools::getValue('email')),
'{shopname}' => 'shop 1',),
Psql(Tools::getValue('email')),
Psql(Tools::getValue('firstname')).' '.Psql(Tools::getValue('lastname')),
$this->context->shop->name
);
}
}
答案 0 :(得分:0)
您需要提供模板路径。
这是邮件功能参数:
/**
* Send Email
*
* @param int $id_lang Language of the email (to translate the template)
* @param string $template Template: the name of template not be a var but a string !
* @param string $subject
* @param string $template_vars
* @param string $to
* @param string $to_name
* @param string $from
* @param string $from_name
* @param array $file_attachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files
* @param bool $modeSMTP
* @param string $template_path
* @param bool $die
* @param string $bcc Bcc recipient
*/
public static function Send($id_lang, $template, $subject, $template_vars, $to,
$to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null,
$template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null, $reply_to = null)
{
这是您的功能(假设您的模板位于模块的mails
目录中):
/*
* Send email to the new employer
* */
public function sendMail()
{
Mail::Send(
$this->context->language->id,
'selcreate_account',
Mail::l('Creation de compte'),
array(
'{firstname}' =>Psql(Tools::getValue('firstname')),
'{lastname}' =>Psql(Tools::getValue('lastname')),
'{passwd}' => Psql(Tools::getValue('passwd')),
'{email}' => Psql(Tools::getValue('email')),
'{shopname}' => 'shop 1',),
Psql(Tools::getValue('email')),
Psql(Tools::getValue('firstname')).' '.Psql(Tools::getValue('lastname')),
$this->context->shop->name,
null,
null,
null,
_PS_MODULE_DIR_.'your_module/mails/'
);
}
答案 1 :(得分:0)
您应在$template_path
中定义目录路径send()
,如
如果要创建模块,则路径应为
_PS_MODULE_DIR_.'yourmodulename/mails/'
希望有帮助。