Saturday, April 17, 2010

PrestaShop Tips - How to BCC (blind carbon copy ) all emails to shop owner or specific email address

In some cases, the shop owner would like to see all emails to be BCC blind carbon copied). In this case, you will need to following code to implement this.

If you are using PrestaShop 1.3x
Modify following file

Modify file name:
Classes/Mail.php

Location 1:
at oringal line 50 , adding following one line (2nd line is existing)
$to_list->addBcc($configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME']);
$to_plugin = $to[0];

Location 2:
at original line 54, comment out existing lines and add following lines
//$to_plugin = $to;
//$to = new Swift_Address($to, $toName);

$to_list = new Swift_RecipientList();
$to_list->addTo($to, $toName);
$to_list->addBcc($configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME']);

$to_plugin = $to;
$to = $to_list;

If you are using PrestaShop 1.4x
it is very simple, you only need to create a override of Mail class

1. create a new file with name Mail.php at following location.

/override/classes/

2. copy following code and paste it into the new created file


<?php
class Mail extends MailCore
{
public static function Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = _PS_MAIL_DIR_, $die = false)
{
//send to customer
$ret = parent::Send($id_lang, $template, $subject, $templateVars, $to, $toName, $from, $fromName, $fileAttachment, $modeSMTP, $templatePath, $die);

//send to Shop Owner
parent::Send($id_lang, $template, $subject, $templateVars, Configuration::get('PS_SHOP_EMAIL'), $toName, $from, $fromName, $fileAttachment, $modeSMTP, $templatePath, $die);

//return result
return $ret;
}
}



Now a ready-made file (PrestaSgop 1.4x only) are available to download from http://addons-modules.com/

12 comments:

Lisa said...

Thanks for the tip and the code mod. Works perfect in PShop version 1.3.2.

Kind regards,
Lisa

Anonymous said...

I tried your code on PS 1.3.7, but it doesnt work correctly. The emails that are send are not properly handled. I get template variables like {owner} and others that should be replaced with content. This does not happen.

It is not needed to set an BCC. You can also add multiple To: and use a batchSend method.

Alvin said...

Thanks for your comment.

I think the code itself should work. The problem you are facing is not with modification code. Your problem is caused by something else. Even you don't use this code, you problem should still there.

But you are correct, it is not necessary to be BCC, you can also add multiple to TO and use a batch send method.

Michael said...

Hello Alvin - this really interests me but i cannot seem to match up where I should add the lines according to where you said they should go. I'm using PSv 1.4.1. Is there any way for me to send you my mail.php file? Thank you for any help you can give me.

Kind regards
Michael

Alvin said...

@Michale,
I just updated the this blog to include a simple way to implement the function in PrestaShop 1.4x.

If you give me your address, I will send you the file directly.

Michael said...

Hi Alvin

Many thanks for posting the solution for PS 1.4.x. I've tested it and it works perfectly, and such an easy method as well. Excellent.
Michael

Alvin said...

You are welcome, Michael.
Yes the 1.4x version of PrestaShop have better architecture, so we have a cleaner and better solutions.

MarWot said...

For PS 1.3.7 the lines are wrong.
Instead of line 50 line 71.
Instead of line 54 line 76. :)

Anonymous said...

Hi Alvin

i am using prestasho 1.4.6.2 and i am using mail alets. It works fine with the orders, but the customer contact form only sends the emails to one account. I tried to use mail forwarding function in gmail but it can only orward to one email. Is there an easy way to forward incoming emails to multiple email accounts?

Thanks

Alvin said...

>I'm using PSv 1.4.1. Is there any way for me to send you my mail.php file? Thank you for any help you can give me.


You can download the code free module here, and modify the code to send to multiple email address
http://addons-modules.com/

Or you can create a mailing list at your mail server, and send the email to the mailing list.

Krithik said...

Thank you very much its very useful for me

Anonymous said...

Hi thanks for the tip. The code is a little different in prestashop 1.5.4 because some of the variables changed name. Here's the updated code:

class Mail extends MailCore
{
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)
{
// send to customer
$ret = parent::Send($id_lang, $template, $subject, $template_vars, $to, $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop);

// send to shop owner
parent::Send($id_lang, $template, $subject, $template_vars, Configuration::get('PS_SHOP_EMAIL'), $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop);

return $ret;
}
}