Jump to content

how to add a mailaddress in bcc just for shipping mail


Recommended Posts

Hi

 

i use 1.6.06

 

for Trustpilot service i would like to add the emailaddress i received (with the customercodein it) just for the shipping email template

 

no i added that mailaddress in modules>mail alerts and that works also but this adds every mail in the alerts to trustpilot

 

best scenario would be that only when products are shipped this will go to their system but that requires me to add that emailaddress to bcc for shipping email template only

 

Is this possible and how?

 

Thank you so much

Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...
  • 3 weeks later...

Sorry to open this old topic again, but did you find any solutions ?

 

I need the same function.

I found this post https://www.prestashop.com/forums/topic/376904-how-to-email-copy-of-terms-and-conditions-for-each-shipped-order/

 

Would that be the right way to do it in Prestashop 1.6.1.4 or should it be done with a override ?

 

I am new to prestashop, so i am not sure if it would be a propper way to do it with changing the core file mail.php.

Link to comment
Share on other sites

  • 1 year later...

i try to make an ovverride to mail,.php adding a bcc email only if template is ="shipped"

 

Don't know if i'm doing it right.

<?php

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, $bcc = null, $reply_to = null)
{
    // add trustpilot SFA 2.0
    if($template == 'shipped')
    {
        $bcc->addBcc('*********@invite.trustpilot.com');
    }      
}

?>

is something that could work?

Edited by ANGELO Vintage (see edit history)
Link to comment
Share on other sites

well $bcc variable is null by default, so this code would fail if that were the case.

$bcc->addBcc('*********@invite.trustpilot.com');

The problem in PS v1.6.1.4 is that it is designed to only allow 1 email in the $bcc.  So in order for your approach to work, you would have to do this instead

$bcc = '*********@invite.trustpilot.com';
Link to comment
Share on other sites

anyway i chekced the Mail.php in 1.6.1.13 and seems is an array of emails

/**
     * Send Email
     *
     * @param int $id_lang Language ID of the email (to translate the template)
     * @param string $template Template: the name of template not be a var but a string !
     * @param string $subject Subject of the email
     * @param string $template_vars Template variables for the email
     * @param string|array $to To email
     * @param string|array $to_name To name
     * @param string $from From email
     * @param string $from_name To email
     * @param array $file_attachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files
     * @param bool $mode_smtp SMTP mode (deprecated)
     * @param string $template_path Template path
     * @param bool $die Die after error
     * @param int $id_shop Shop ID
     * @param string|array $bcc Bcc recipient(s) (email address)
     * @param string $reply_to Email address for setting the Reply-To header
     * @return bool|int Whether sending was successful. If not at all, false, otherwise amount of recipients succeeded.
     */

I've check better the documentation and i create this code but seems not working, It gives me back a 500 server error when the Send function is called (also during user registration for example).

<?php

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, $bcc = null, $reply_to = null)
{
    // add trustpilot SFA 2.0
    if($template == 'shipped')
    {
        $bcc = '[email protected]';
    }      
    
    // send to customer
    return parent::Send($id_lang, $template, $subject, $template_vars, $to, $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop, $bcc, $reply_to);
}
?>

I place the Mail.php containing the code above in /override/classes folder, deleted the /cache/class_index.php file too.

I've not find why it not work :(

Link to comment
Share on other sites

Error 500 is most probably a syntax or logical error in your php.

 

1. Syntax check, for example here:

http://www.meandeviation.com/tutorials/learnphp/php-syntax-check/v5-3/syntax-check.php

Result: the first paranthesis was not closed before the end of php at line 17.

The correct syntax for adding a bcc directly would be:

$message->addBcc($addr);

So the additional part would be:

if($template == 'shipped')
{
$message->addBcc('[email protected]');
}

IMPORTANT:

 

This part must be, after the object $message is created, which is at about line 185. If you put it in before, you also get an error.

But the way with calling parent could also work as soon as you fix the syntax.

   $message = Swift_Message::newInstance();

Feedback is appreciated.

Edited by Scully (see edit history)
Link to comment
Share on other sites

Tipp:

it's always helpful to use online php syntax checker. Modern editors have a lot of built-in-functionality to avoid syntax probs, but sometimes you get lost with lots of if-then-else or paranthesis problems like this one.

Link to comment
Share on other sites

  • 2 weeks later...

hi Scully, 

thank you for yuo answer, i still using this version and seems working:

 

<?php
/*
 MODIFIED VERSION TO SUPPORT TRUSTPILOT SEND ON SHIPPED STATUS CHANGE
*/


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, $bcc = null, $reply_to = null)
    {


        if($template == 'shipped') { $bcc = array('[email protected]'); }


        return parent::Send($id_lang, $template, $subject, $template_vars, $to,
            $to_name, $from, $from_name, $file_attachment, $mode_smtp,
            $template_path, $die, $id_shop, $bcc, $reply_to);


    }


}

you suggest anyway to change the line:

if($template == 'shipped') { $bcc = array('[email protected]'); }

with

if($template == 'shipped'){  $message->addBcc('[email protected]'); }

Is more correct?

 

Ty

Link to comment
Share on other sites

If it's working, it's good.

My version has the advantage of NOT overwriting existing bcc if they exist.

When you run your code and for example Mail Alerts or another Module has already set a BCC, it'l get lost with yours.

 

Also note that my code must be inserted after the $message object hast been created.

Link to comment
Share on other sites

Seems to me you need to check the existing $bcc value first

 

1) Check if it is null.  If it is null then just use your existing code

2) If it is not null, then check if it is an array. 

2a) If it is an array, then you can just push your new email to the existing array. 

2b) If it is not an array, then whatever called this function is doing it wrong, and you should convert $bcc to an array, and then add the emails to it.

Link to comment
Share on other sites

Seems to me you need to check the existing $bcc value first

 

1) Check if it is null.  If it is null then just use your existing code

2) If it is not null, then check if it is an array. 

2a) If it is an array, then you can just push your new email to the existing array. 

2b) If it is not an array, then whatever called this function is doing it wrong, and you should convert $bcc to an array, and then add the emails to it.

 

ty i will follow your suggestion!

Link to comment
Share on other sites

×
×
  • Create New...