Jump to content

[SOLVED] Add more than one email for customer service in contact form


nioc22
 Share

Recommended Posts

Hello community!

 

I hope you are all well! I need your help for a little problem that I can't get through!

 

In the contact form you can choose between  Webmaster or Customer Service (which is differents e-mails) before an email is sent. 

 

I set an email for Customer Service, but we are 2 (sometime 3) peoples to manage this service and to answer to the customer.

 

Is it possible to have 2 or more email set in Customer Service? I tried to separate mail by coma (,) but I got ''invalid mail'' when I did it. And it will be great if all the customer service team will received the notification from the contact form. Otherwise we always need to check if we received some mail from a customer..

 

 

Thank you in advance for your help.

 

Nico

Share this post


Link to post
Share on other sites

Hi Nico,

Try this:

 

 

Edit or override the file /classes/Validate.php (make backup, just in case!!!) (Sample code of PS 1.6.0.5)

 

and edit the function: (add red code)

 
public static function isEmail($email)
{
  $emails = explode(",", $email); //!!!Pas, make more recipients in one string possible
  $return = true;
  foreach ($emails as $tmpemail)
    $return= ($return && !empty($email) && preg_match(Tools::cleanNonUnicodeSupport('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z\p{L}0-9]+$/ui'), $tmpemail));
 
  return $return;
 
 
  // return !empty($email) && preg_match(Tools::cleanNonUnicodeSupport('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z\p{L}0-9]+$/ui'), $email);
 
}
 
and save.
This code allows for a comma in the recipients Email address input field (Email of Webmaster, customer service etc)
So you can now add
 
 
 
Then, override or edit file /classes/Mail.php  (again, make backup!) (add red code)
 
and edit function:
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)
 

...

if (!Validate::isMailSubject($subject))
{
  Tools::dieOrLog(Tools::displayError('Error: invalid e-mail subject'), $die);
  return false;
}
 
/* Construct multiple recipients list if needed */
 
if (strpos($to, ',') !==false) // Allow multiple recipients in one string...
  $to = explode(',', $to);
 
$to_list = new Swift_RecipientList();
if (is_array($to) && isset($to))
{
 ...
 
 
and save.
This will split/transform the recipients string $to in a recipients array $to, which will then be given to the rest of the mail function as usual.
 
I hope that does the trick.
 
pascal.
  • Like 4

Share this post


Link to post
Share on other sites

(N.B. Another option is to do it outside Prestashop:

add a forward rule to your Email box. Most Email providers can forward new Emails to other email addresses on receipt, depending on the sender field, recipient field, subject text etc.). So then just forward a copy to the other team members...

 

My 2 cents,

pascal

Share this post


Link to post
Share on other sites

Thanks a lot PascalVG.

 

Your answer was super fast!!

 

I just came back from a long week end but I will test it for sure tomorow!

 

I will write a update after I test it!! 

 

Thanks again!

Share this post


Link to post
Share on other sites

Hello PascalVG

 

So I tried your first solution today and it work like a charm on my shop. Now I can set multiple email for the customer service. It's perfect!!

 

For info my shop is on 1.5.4.1 version.

 

Thanks again for your super fast  and well explain help!! You'r the best!

 

Nico

Share this post


Link to post
Share on other sites

  • 1 year later...

Hello Pascal

 

I tried this on a prestashop 1.6.1.3 by editing the classes/Validate.php and the classes/Mail.php but it still giving me an error when i add more than one email separated by comma

 

any suggestions ?

 

Best regards,

Majd

Share this post


Link to post
Share on other sites

  • 8 months later...

After making the changes as shown above, I was able to add one more mail id.

But, when the form is submitted, it shows error (No details of error, screen shot attached). But when I press the Send button again, the form gets submitted.

 

How to correct it.post-1117446-0-68478900-1474962264_thumb.png

Edited by raunhar (see edit history)
  • Like 2

Share this post


Link to post
Share on other sites

  • 5 months later...
  • 1 year later...
  • 3 years later...
On 4/30/2014 at 9:13 PM, PascalVG said:

Hi Nico,

Try this:

 

 

Edit or override the file /classes/Validate.php (make backup, just in case!!!) (Sample code of PS 1.6.0.5)

 

and edit the function: (add red code)

 
public static function isEmail($email)
{
  $emails = explode(",", $email); //!!!Pas, make more recipients in one string possible
  $return = true;
  foreach ($emails as $tmpemail)
    $return= ($return && !empty($email) && preg_match(Tools::cleanNonUnicodeSupport('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z\p{L}0-9]+$/ui'), $tmpemail));
 
  return $return;
 
 
  // return !empty($email) && preg_match(Tools::cleanNonUnicodeSupport('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z\p{L}0-9]+$/ui'), $email);
 
}
 
and save.
This code allows for a comma in the recipients Email address input field (Email of Webmaster, customer service etc)
So you can now add
 
 
 
Then, override or edit file /classes/Mail.php  (again, make backup!) (add red code)
 
and edit function:
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)
 

...

if (!Validate::isMailSubject($subject))
{
  Tools::dieOrLog(Tools::displayError('Error: invalid e-mail subject'), $die);
  return false;
}
 
/* Construct multiple recipients list if needed */
 
if (strpos($to, ',') !==false) // Allow multiple recipients in one string...
  $to = explode(',', $to);
 
$to_list = new Swift_RecipientList();
if (is_array($to) && isset($to))
{
 ...
 
 
and save.
This will split/transform the recipients string $to in a recipients array $to, which will then be given to the rest of the mail function as usual.
 
I hope that does the trick.
 
pascal.

Hi Pascal,
I've tried your solution in presta 1.6.1.24 but doesn't work...
Do you know other way to have two emails in PS_SHOP_MAIL?
If you could help see my post here.

Thanks for all the help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More