Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added section to send email: custom template #339

Merged
merged 2 commits into from Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
node_modules/
hugo
.idea/
.vscode/
luigimassa marked this conversation as resolved.
Show resolved Hide resolved
luigimassa marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 40 additions & 3 deletions src/content/1.7/development/mail.md
Expand Up @@ -7,12 +7,10 @@ weight: 70

## Using the `Mail::send()` method


{{% notice note %}}
The `Mail` core class extends [ObjectModel](/1.7/development/database/objectmodel)
{{% /notice %}}


{{% notice note %}}
This example is assuming you are using in a controller named `mycontroller` of a module named `mymodule`
{{% /notice %}}
Expand All @@ -32,7 +30,7 @@ class mymodulemycontrollerModuleFrontController extends ModuleFrontController
'{email}' => Configuration::get('PS_SHOP_EMAIL'), // sender email address
'{message}' => 'Hello world' // email content
),
Configuration::get('PS_SHOP_EMAIL'), // receiver email address
Configuration::get('PS_SHOP_EMAIL'), // receiver email address
NULL, //receiver name
NULL, //from email address
NULL //from name
Expand All @@ -44,3 +42,42 @@ class mymodulemycontrollerModuleFrontController extends ModuleFrontController
{{% notice tip %}}
Prestashop will use the Shop Configuration to decide if use `smtp` connection or php `mail` function so check it out on backoffice or in `app/config/parameter.php`
{{% /notice %}}

## Add custom template

`Mail::send` has some parameters. You can specify your emails templates path of your module in parameter `templatePath`.

In your module you must create the subfolder `mails` and then a sub folder with languages. Example: `modules\yourmodulename\mails\en` for english.

In this folder you do create 2 files: one with extension `.html` and one with extension `.txt`.

The name of the template files is in second parameter. In the under example the template name is `contact`. So you do create 2 files in mails subfolders of your module: `modules\yourmodulename\mails\en\contact.html` and `modules\yourmodulename\mails\en\contact.txt`.

After installation, the templates email files are moved under the active folder theme: `theme\classic\modules\yourmodulename\mails\en\....`.

```php
class mymodulemycontrollerModuleFrontController extends ModuleFrontController
{

public function initContent()
{
parent::initContent();
Mail::Send(
(int)(Configuration::get('PS_LANG_DEFAULT')), // defaut language id
'contact', // email template file to be use
' Module Installation', // email subject
array(
'{email}' => Configuration::get('PS_SHOP_EMAIL'), // sender email address
'{message}' => 'Hello world' // email content
),
Configuration::get('PS_SHOP_EMAIL'), // receiver email address
NULL, //receiver name
NULL, //from email address
NULL, //from name
NULL, //file attachment
NULL, //mode smtp
'/modules/yourmodulename/mails' //custom template path
luigimassa marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
```