Jump to content

Order mails BCC


kobjectt

Recommended Posts

if you want to receive exactly the same emails as customer receives (and all the messages that your shop sends) you can add setBcc() function to mail::send class

 

open classes/Mail.php - you can find there public static function Send()

 

before 

$send = $swift->send($message); 

add:

$message->setBcc(array('[email protected]'))

so prestashop will send blind carbon copy emails to [email protected]

  • Like 1
Link to comment
Share on other sites

if you want to receive exactly the same emails as customer receives (and all the messages that your shop sends) you can add setBcc() function to mail::send class

 

open classes/Mail.php - you can find there public static function Send()

 

before 

$send = $swift->send($message); 

add:

$message->setBcc(array('[email protected]'))

so prestashop will send blind carbon copy emails to [email protected]

 

Thanks for the fast reply,

 

This seems something i need. But i only want the mails with PDF included to have a BCC. The other mails not!

Link to comment
Share on other sites

 

you can create if condition that will check if mail has a file attachments: $file_attachment

if ($file_attachment && !empty($file_attachment)) {
$message->setBcc(array('[email protected]'))
}

 

I got something like this now:

 

          
  /* Send mail */
            $message->setFrom(array($from => $from_name));
            $message->setBcc(array('mail@mail'))
            $send = $swift->send($message);


            ShopUrl::resetMainDomainCache();


            if ($send && Configuration::get('PS_LOG_EMAILS')) {
                $mail = new Mail();
                $mail->template = Tools::substr($template, 0, 62);
                $mail->subject = Tools::substr($subject, 0, 254);
                $mail->id_lang = (int)$id_lang;
                $recipients_to = $message->getTo();
                $recipients_cc = $message->getCc();
                $recipients_bcc = $message->getBcc();
                if (!is_array($recipients_to)) {
                    $recipients_to = array();
                }
                if (!is_array($recipients_cc)) {
                    $recipients_cc = array();
                }
                if (!is_array($recipients_bcc)) {
                    $recipients_bcc = array();
                }
                if ($file_attachment && !empty($file_attachment)) {
                $message->setBcc(array('[email protected]'))
                }
 
This is how it should be?
Link to comment
Share on other sites

im not sure whats up,
i asked about

you mean that you receive bcc no matter if mail has attachment or not?

 
then you confirmed

Yes,

 
but you also said that no email is delivered to your mailbox

the mail for only mails with attachments wont recieve any mails

 

so let's clarify what's up now because im a little confused :P thank you!

Link to comment
Share on other sites

im not sure whats up,

i asked about

 

then you confirmed

 

but you also said that no email is delivered to your mailbox

 

so let's clarify what's up now because im a little confused :P thank you!

 

First off all nothing seems to work, but after some little tweaking the BBC function seems to work fine. But this function works only for all the mails that has been sended through out the Prestashop mail.

 

The configuration to add BBC only to mails with a attachment is not working at the moment, this is what i have now!

 $message->setFrom(array($from => $from_name));
            $message->setBcc(array('[email protected]'));
            $send = $swift->send($message);


            ShopUrl::resetMainDomainCache();


            if ($file_attachment && !empty($file_attachment)) {
                $message->setBcc(array('[email protected]'));
                }


            if ($send && Configuration::get('PS_LOG_EMAILS')) {
                $mail = new Mail();
                $mail->template = Tools::substr($template, 0, 62);
                $mail->subject = Tools::substr($subject, 0, 254);
                $mail->id_lang = (int)$id_lang;
                $recipients_to = $message->getTo();
                $recipients_cc = $message->getCc();
                $recipients_bcc = $message->getBcc();
                if (!is_array($recipients_to)) {
                    $recipients_to = array();
                }
                if (!is_array($recipients_cc)) {
                    $recipients_cc = array();
                }
                if (!is_array($recipients_bcc)) {
                    $recipients_bcc = array();
                }
So the following part is not working ATM:
 
 if ($file_attachment && !empty($file_attachment)) {
                $message->setBcc(array('[email protected]'));
                }

Link to comment
Share on other sites

  • 3 weeks later...

if you want to receive exactly the same emails as customer receives (and all the messages that your shop sends) you can add setBcc() function to mail::send class

 

open classes/Mail.php - you can find there public static function Send()

 

before 

$send = $swift->send($message); 

add:

$message->setBcc(array('[email protected]'))

so prestashop will send blind carbon copy emails to [email protected]

 

 

Thx! 

 

After the last update to 1.6.1.6 my former customisation (it was on tools/swift.php) did no longer effect.

 

This works like a charme!

Link to comment
Share on other sites

  • 1 month later...

Hi Vekia:

 

if you want to receive exactly the same emails as customer receives (and all the messages that your shop sends) you can add setBcc() function to mail::send class

 

open classes/Mail.php - you can find there public static function Send()

 

before 

$send = $swift->send($message); 

add:

$message->setBcc(array('[email protected]'))

so prestashop will send blind carbon copy emails to [email protected]

 

I did this, but it does not work , please help!!! , PS 1.6.1.6 

Thanks

Link to comment
Share on other sites

  • 1 year later...
  • 5 months later...
On 19/8/2016 at 14:29, vekia said:

se vuoi ricevere esattamente le stesse email ricevute dal cliente (e tutti i messaggi che il tuo negozio invia) puoi aggiungere la funzione setBcc () alla classe mail :: send

 

open classes / Mail.php - puoi trovare lì la funzione statica pubblica Send ()

 

prima 


 

Inserisci:


quindi prestashop invierà e-mail in copia carbone a [email protected]

hi, i have try your adivce, and mail bcc sent ok, but there isnt any attached file....

Link to comment
Share on other sites

  • 9 months later...
On 8/19/2016 at 2:29 PM, vekia said:

if you want to receive exactly the same emails as customer receives (and all the messages that your shop sends) you can add setBcc() function to mail::send class

 

open classes/Mail.php - you can find there public static function Send()

 

before 


$send = $swift->send($message); 

add:


$message->setBcc(array('[email protected]'))

so prestashop will send blind carbon copy emails to [email protected]

With Prestashop 1.7.5 didn't work 😐

Link to comment
Share on other sites

  • 9 months later...
  • 2 months later...

A proper method for the prestashop 1.7 version is to use the hook actionEmailSendBefore in a module.
In this hook  you have access to all the emails vars : cf. https://github.com/PrestaShop/PrestaShop/blob/develop/classes/Mail.php#L154

Then in your module you can add a condition on the template send with something like this

    /**
     * Executed before an email is end
     * @param array $params
     * @return void
     */
    public function hookActionEmailSendBefore($params)
    {
        if (
            $params['template'] == 'template_code'
        )
        {
          $params['bcc'] = ['[email protected]'];
        }
     }

 

Link to comment
Share on other sites

On 8/19/2016 at 4:25 PM, vekia said:

Thank you hhennes for your suggestion, but actually to follow it I need some insights on php and in prestashop modues making ( i'm studying..;-). I Thought a more simple action similar to the method suggested by vekia working on Mail.php ...  

 

 you can create if condition that will check if mail has a file attachments: $file_attachment


if ($file_attachment && !empty($file_attachment)) {
$message->setBcc(array('[email protected]'))
}

 

Link to comment
Share on other sites

Hello,

If you are studying, the best advise i can give you is to try to do it the right way directly :)
Avoid to use override when they are not necessary.

If you still need to do it directly on Mail class, simply add a condition on the template name

if ( $template == 'your_template){
 //Add bcc here
} 


Regards

  • Like 1
Link to comment
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
×
×
  • Create New...