Mail Sending in Prestashop 1.4

Today we help developers figure out how to send mails in Prestashop. When you read this post all the way through, you will be able to deliver this kind of messages to customers:

Go read how to do it!

In Prestashop there is the class Mail to work with mails, which is available in a standard folder with all “classes”. Mail is the basic class, but it uses the “Swift” library that is activated in the file with class description. Mail class has only three methods, all being static, i.e you can use them without class instance creation.

Time to send the message.

First, we create a template for it. The template should include two formats: HTML and TXT. Templates are created for each language separately. We create a new folder and name it “mails” in the module folder, then we add extra folders in there for each language and name them: de, en, es, fr, it (Prestashop has 5 languages by default). Each language folder mush have two template files (HTML and TXT). These files names can be arbitrary.
Consider the example of HTML template file:

1

2

3

4

5

<html>

<body>

<h1>Hi, {firstname} {lastname}!</h1>

</body>

</html>

TXT template file example: Hi, {firstname} {lastname}! “{firstname}” and “{lastname}” – are variables that will be replaced by necessary content (any number can be created). Now let’s write a code that will send a message to the customer with test@test.test email:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

require(dirname(__FILE__).'/config/config.inc.php');

require_once(dirname(__FILE__).'/init.php');

$customer=newCustomer();

$customer->getByEmail('test@test.test');

//Set the variables for the template:

$templateVars['{firstname}']=$customer->firstname;

$templateVars['{lastname}']=$customer->lastname;

$templateVars['{src_img}']=_PS_BASE_URL_.__PS_BASE_URI__.'download/blog_belvg.png';//Image to be displayed in the message

Aleksandr Simonchik is a professional Magento and Prestashop developer. He has created a lot of great modules for BelVG eCommerce Development Company, among which are Prestashop Facebook all in one, Product Links, Events Wall and more.

Internet and eBusiness technologies as well as control systems of databases he has mastered include PHP, JavaScript, DHTML/HTML, CSS, XML/XSLT, MS SQL Server, MySQL, DB2 and InterBase. Aleksandr is also an expert in UML and Rational Rose.

He is sure that the most important thing in any project is professional satisfaction you get after it’s accomplished. Aleksandr’s major hobby is Laser tag, and main inspirer – his adorable Yorkshire terrier.

Any Magento or PrestaShop merchant – big or small – can sell on Facebook, significantly boosting his/her sales.

Here are a few examples for that:

The jewelry designer Nava Zahavi who started with only 100 fans on Facebook. Running a small budget Facebook ads campaign driving traffic to her Facebook store, she made 400% Return on Investment (ROI) selling on Facebook.

The Scandinavian fashion brand OnePiece, sold over 1,000 items in 24 hours offering a group deal inside their Facebook store. In addition, this brand has increased its Facebook community by 4,000 fans in those 24 hours.

The New York Times has recently covered that The Polkadot Alley company switch from e-Commerce to f-Commerce (Facebook-Commerce) increased the company’s sales from $400K to $1.5M over the period of one year.

The average conversion rate of Facebook stores that we see is 20%! As an online merchant, you can appreciate this very high number.

I know this post is old but I am trying it on version 1.615 and it gives the following error
“Parse error: syntax error, unexpected ‘&’ in /home/mydomain.com/public_html/shop/templatesendtest.php on line 5”

I put the php file in the root of my shop

line 5 is : $customer->getByEmail(‘test@test.test’); where I changed test@test.test to my email.