Question

I've looked everywhere and can't find an answer to my problem. I want to unactivate user account on registration and afterwards activate it in BackOffice. I managed to do this but I want to send user an email when his account is activated so i added a button beside activate/unactivate radio button, i added the following in AdminCustomers.php

 <input type="submit" value="'.$this->l('   Send Email to inform user   ').'"/>

But i don't know how to send email. My question may seem very simple to you but I am new to php/html so it is a bit hard for me. I have searched and found many examples to send email but none of them seems to be working.

EDIT: The reason i'm doing this is that we have two types of clients: individuals and companies. And for companies we need to verify the provided info (ex:VAT number). And then activate the account because it gives them access to special prices.

Was it helpful?

Solution 2

I ended up creating a module for this. It works perfectly with Prestashop 1.5.

OTHER TIPS

Where are you activating the account? You should just add code to send the email after the account has been activated - it doesn't seem to make sense to add an additional step (that the administrator could forget to take).

Within a module I would use something like the following:

private function _emailNewAccount($customer, $address, $messages)
  {
    $configuration = Configuration::getMultiple(array('PS_LANG_DEFAULT', 'PS_SHOP_EMAIL', 'PS_SHOP_NAME'));
    $id_lang = (int)$configuration['PS_LANG_DEFAULT'];
    $template = 'new_account';
$subject = $this->l('New Account', $id_lang);
    $templateVars = array(
      '{firstname}' => $customer->firstname,
      '{lastname}' => $customer->lastname,
      '{address1}' => $address->address1,
      '{address2}' => !empty($address->address2) ? $address->address2 : $this->l('--',     $id_lang),
      '{city}' => $address->city,
      '{postcode}' => $address->postcode,
      '{email}' => $customer->email,
      '{messages}' => is_array($messages) ? implode("\n", $messages) : (isset($messages) ? $messages : ''),
      '{phone}' => !empty($address->phone) ? $address->phone : $this->l('n/a', $id_lang),
      '{mobile}' => !empty($address->phone_mobile) ? $address->phone_mobile : $this->l('n/a', $id_lang),
      '{customer_id}' => (int)$customer->id
    );
    $iso = Language::getIsoById((int)($id_lang));
    if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.txt') AND file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.html'))
      Mail::Send($id_lang, $template, $subject, $templateVars, $customer->email,$customer->firstname.' '.$customer->lastname, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], NULL, NULL, dirname(__FILE__).'/mails/');
}

Obviously you also need to create the corresponding text and html email templates. These would be in my module dorectory in this case: /modules/mymodulename/mails/en/new_account.html /modules/mymodulename/mails/en/new_account.txt

You use the fields defined above within the template, so for the text-only template you might have in new_account.txt:

Hi {firstname} {lastname},

 You have just registered on {shop_name}.

 Address:

 {address1}
 {address2}
 {city}, {postcode}
 Telephone: {phone}, Mobile: {mobile}

 {messages}

It might be good if you include in your question what you have tried so far....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top