Get email notifications for new customers registrations

In this quick tip we will see how to enable email notifications for when a new client registers to our shop.

The Plan

Since we want to be informed when a new user registers, we need to add our code snippets right where the user itself is notified about it. For this reason, we will be extending the sendConfirmationMail method of the AuthController.php file, and create a new email template as well.

The AuthController override

As always it’s good practice to use overrides instead of modifying core files directly (to preserve changes after updates). Therefore, create a new file called AuthController.php inside override/controllers/front. Inside php tags, paste the following override code:

[php]
Class AuthController extends AuthControllerCore
{

}
[/php]

As mentioned above, we need to extend the default sendConfirmationMail method, so let’s grab it from the original controller and paste it inside our override (this is from Prestashop 1.6.0.9):

[php]
Class AuthController extends AuthControllerCore
{
protected function sendConfirmationMail(Customer $customer)
{
if (!Configuration::get(‘PS_CUSTOMER_CREATION_EMAIL’))
return true;

return Mail::Send(
$this->context->language->id,
‘account’,
Mail::l(‘Welcome!’),
array(
‘{firstname}’ => $customer->firstname,
‘{lastname}’ => $customer->lastname,
‘{email}’ => $customer->email,
‘{passwd}’ => Tools::getValue(‘passwd’)),
$customer->email,
$customer->firstname.’ ‘.$customer->lastname
);
}

}
[/php]

Just in case, let’s make sure emails still work. Erase the class_index.php located in the cache/ folder. Then, try registering a new user and make sure you get the confirmation email. If you do, it’s time to add another rule to inform the admin; right before the return, add:

[php]
Mail::Send(
Configuration::get(‘PS_LANG_DEFAULT’),
‘account_for_admin’,
Mail::l(‘New client!’),
array(
‘{firstname}’ => $customer->firstname,
‘{lastname}’ => $customer->lastname,
‘{email}’ => $customer->email
),
Configuration::get(‘PS_SHOP_EMAIL’),
Configuration::get(‘PS_SHOP_NAME’)
);
[/php]

Explanation: we just copied the returned code and adapted it to our needs; first, instead of using the customer language to grab the email template, we use the shop’s default one. This way we don’t need to create multiple/translated templates. Then, we pass in ‘account_for_admin’ as email template name; it doesn’t exist yet so don’t try running a new registration or it won’t work. Then, to preserve the user’s credentials we get rid of the password. Lastly we set the “to” parameter to the shop’s email, and set the receiver to the shop’s name. That’s all there is to it. Let’s now create that template.

Creating a new email template

Instead of proceeding from scratch, I generally copy an existing html template, to have them all uniform. Let’s use that user welcome as base. Reach mails/en (or whatever your default language’s ISO is, you can check it in the back office, localization, languages); Clone both account.html and account.txt, and then rename them to account_for_admin.html and account_for_admin.txt. Open up the .txt file, it will look something like:

[html]

[{shop_url}]

Hi {firstname} {lastname},

Thank you for creating a customer account at {shop_name}.

Here are your login details:

E-MAIL ADDRESS: {email}

PASSWORD: {passwd}

Important Security Tips:

* Always keep your account details safe.

* Never disclose your login details to anyone.

* Change your password regularly.

* Should you suspect someone is using your account illegally, please
notify us immediately.

You can now place orders on our shop: {shop_name}
[{shop_url}]

{shop_name} [{shop_url}] powered by
PrestaShop(tm) [http://www.prestashop.com/]

[/html]

Let’s modify it so to fit our needs:

[html]

[{shop_url}]

Hi!

A new customer just signed up for an account at {shop_name}.

Here are the details:

E-MAIL ADDRESS: {email}

NAME: {firstname} {lastname}

[/html]

Then, apply the same modifications to the html file (please note I am only copying relevant parts of the template):

[html]

<tr>
<td align="center" class="titleblock" style="padding:7px 0">
<font size="2" face="Open-sans, sans-serif" color="#555454">
<span class="title" style="font-weight:500;font-size:28px;text-transform:uppercase;line-height:33px">Hi {firstname} {lastname},</span><br/>
<span class="subtitle" style="font-weight:500;font-size:16px;text-transform:uppercase;line-height:25px">Thank you for creating a customer account at {shop_name}.</span>
</font>
</td>
</tr>
[/html]

To

[html]

<tr>
<td align="center" class="titleblock" style="padding:7px 0">
<font size="2" face="Open-sans, sans-serif" color="#555454">
<span class="title" style="font-weight:500;font-size:28px;text-transform:uppercase;line-height:33px">Hi!</span><br/>
<span class="subtitle" style="font-weight:500;font-size:16px;text-transform:uppercase;line-height:25px">A new customer just signed up for an account at {shop_name}.</span>
</font>
</td>
</tr>
[/html]

Then

[html]

<tr>
<td class="box" style="border:1px solid #D6D4D4;background-color:#f8f8f8;padding:7px 0">
<table class="table" style="width:100%">
<tr>
<td width="10" style="padding:7px 0">&nbsp;</td>
<td style="padding:7px 0">
<font size="2" face="Open-sans, sans-serif" color="#555454">
<p data-html-only="1" style="border-bottom:1px solid #D6D4D4;margin:3px 0 7px;text-transform:uppercase;font-weight:500;font-size:18px;padding-bottom:10px">
Your {shop_name} login details </p>
<span style="color:#777">
Here are your login details:<br />
<span style="color:#333"><strong>E-mail address: <a href="mailto:{email}" style="color:#337ff1">{email}</a></strong></span><br />
<span style="color:#333"><strong>Password:</strong></span> {passwd}
</span>
</font>
</td>
<td width="10" style="padding:7px 0">&nbsp;</td>
</tr>
</table>
</td>
</tr>
[/html]

To

[html]

<tr>
<td class="box" style="border:1px solid #D6D4D4;background-color:#f8f8f8;padding:7px 0">
<table class="table" style="width:100%">
<tr>
<td width="10" style="padding:7px 0">&nbsp;</td>
<td style="padding:7px 0">
<font size="2" face="Open-sans, sans-serif" color="#555454">
<p data-html-only="1" style="border-bottom:1px solid #D6D4D4;margin:3px 0 7px;text-transform:uppercase;font-weight:500;font-size:18px;padding-bottom:10px">
Your {shop_name} login details </p>
<span style="color:#777">
Here are your login details:<br />
<span style="color:#333"><strong>E-mail address: <a href="mailto:{email}" style="color:#337ff1">{email}</a></strong></span><br />
<span style="color:#333"><strong>Password:</strong></span> {passwd}
</span>
</font>
</td>
<td width="10" style="padding:7px 0">&nbsp;</td>
</tr>
</table>
</td>
</tr>
[/html]

Lastly, you can get rid of this:

[html]
<tr>
<td class="space_footer" style="padding:0!important">&nbsp;</td>
</tr>
<tr>
<td class="box" style="border:1px solid #D6D4D4;background-color:#f8f8f8;padding:7px 0">
<table class="table" style="width:100%">
<tr>
<td width="10" style="padding:7px 0">&nbsp;</td>
<td style="padding:7px 0">
<font size="2" face="Open-sans, sans-serif" color="#555454">
<p style="border-bottom:1px solid #D6D4D4;margin:3px 0 7px;text-transform:uppercase;font-weight:500;font-size:18px;padding-bottom:10px">Important Security Tips:</p>
<ol style="margin-bottom:0">
<li>Always keep your account details safe.</li>
<li>Never disclose your login details to anyone.</li>
<li>Change your password regularly.</li>
<li>Should you suspect someone is using your account illegally, please notify us immediately.</li>
</ol>
</font>
</td>
<td width="10" style="padding:7px 0">&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="space_footer" style="padding:0!important">&nbsp;</td>
</tr>
<tr>
<td class="linkbelow" style="padding:7px 0">
<font size="2" face="Open-sans, sans-serif" color="#555454">
<span>You can now place orders on our shop: <a href="{shop_url}" style="color:#337ff1">{shop_name}</a></span>
</font>
</td>
</tr>

<tr>
<td class="space_footer" style="padding:0!important">&nbsp;</td>
</tr>
<tr>
<td class="footer" style="border-top:4px solid #333333;padding:7px 0">
<span><a href="{shop_url}" style="color:#337ff1">{shop_name}</a> powered by <a href="http://www.prestashop.com/" style="color:#337ff1">PrestaShop&trade;</a></span>
</td>
</tr>
</table>
</td>
<td class="space" style="width:20px;padding:7px 0">&nbsp;</td>
</tr>

[/html]

And it’s done! Time to test the outcome!

Troubleshooting

When dealing with emails and Prestashop, there is a high chance of failure. Don’t be discouraged if if doesn’t work at the first attempt, and check the following:

  • – Send out a test email from advanced parameters -> emails to your mail address
  • – Make sure it didn’t end up in the spam folder
  • – Double-check the new template name, it must be account_for_admin everywhere
  • – Make sure you added the template to the correct iso folder. If unsure, clone it to every of them

If you still don’t receive the email, it’s worth trying to kill the Mail::Send method in case of failure, by using the following code instead:

[php]
Mail::Send(
Configuration::get(‘PS_LANG_DEFAULT’),
‘account_for_admin’,
Mail::l(‘New client!’),
array(
‘{firstname}’ => $customer->firstname,
‘{lastname}’ => $customer->lastname,
‘{email}’ => $customer->email
),
Configuration::get(‘PS_SHOP_EMAIL’),
Configuration::get(‘PS_SHOP_NAME’),
null,null,null,null,_PS_MAIL_DIR_,true
);
[/php]

The last parameter I passed in is telling the method to die in case of failure. If that happens, you should be given more info about what went wrong.

Looking for quality PrestaShop hosting? Check out Arvixe Web Solutions.

Tags: , , | Posted under PrestaShop | RSS 2.0

Author Spotlight

Fabio Porta

Fabio has been involved in web development and design since 2005, when launched his first website at the age of 16. He’s now highly skilled in both client and server side development, along with design, and since August 2012 runs a successful website about PrestaShop tutorials and Prestashop Modules called Nemo’s Post Scriptum, at http://nemops.com

Leave a Reply

Your email address will not be published. Required fields are marked *