Jump to content

[solved] multiple email sending


Recommended Posts

hello everyone
I have an old module decommissioned by the developer that sends the cart to the email indicated in the sending form

I would need to receive the same email to another email address

I've been trying to figure out how to do it all day but without success

I think I understood that the code that sends the email is this

 

		if (!count($this->errors)) {
                    if (@Mail::Send(
                        (int)$currentCart->id_lang,
                        'shopping_cart',
                        Mail::l('Carrello condiviso', (int)$currentCart->id_lang),
                        $templateVars,
                        $email,
                        $name,
                        $this->context->customer->email,
                        $this->context->shop->name,
                        $file_attachement, null, $this->module->getLocalPath() . 'mails/'
                    )) {
                        $ids = $this->getIdCartRules($currentCart);
                        // Add log when send mail to guest success!
                        if (!Db::getInstance()->insert('ets_savemycart',
                            [
                                'id_cart' => (int)$currentCart->id,
                                'token' => $token,
                                'cart_rules' => implode(',',$ids),
                            ]
                        )) {
                            $this->errors[] = $this->module->l('Adding log failed.', 'submit');
                        }
                        die(json_encode([
                            'ok' => 1,
                            'msg' => $this->module->l('Mail sent successfully.', 'submit')
                        ]));
                    } else
                        $this->errors[] = $this->module->l('Sending mail failed.', 'submit');
                }

I tried adding

$email = $email .', [email protected]';

but it doesn't work

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

38 minutes ago, overbags said:

hello everyone
I have an old module decommissioned by the developer that sends the cart to the email indicated in the sending form

I would need to receive the same email to another email address

I've been trying to figure out how to do it all day but without success

I think I understood that the code that sends the email is this

 

		if (!count($this->errors)) {
                    if (@Mail::Send(
                        (int)$currentCart->id_lang,
                        'shopping_cart',
                        Mail::l('Carrello condiviso', (int)$currentCart->id_lang),
                        $templateVars,
                        $email,
                        $name,
                        $this->context->customer->email,
                        $this->context->shop->name,
                        $file_attachement, null, $this->module->getLocalPath() . 'mails/'
                    )) {
                        $ids = $this->getIdCartRules($currentCart);
                        // Add log when send mail to guest success!
                        if (!Db::getInstance()->insert('ets_savemycart',
                            [
                                'id_cart' => (int)$currentCart->id,
                                'token' => $token,
                                'cart_rules' => implode(',',$ids),
                            ]
                        )) {
                            $this->errors[] = $this->module->l('Adding log failed.', 'submit');
                        }
                        die(json_encode([
                            'ok' => 1,
                            'msg' => $this->module->l('Mail sent successfully.', 'submit')
                        ]));
                    } else
                        $this->errors[] = $this->module->l('Sending mail failed.', 'submit');
                }

I tried adding

$email = $email .', [email protected]';

but it doesn't work

What about:

if (!count($this->errors)) {
    $mailSent = Mail::Send(
        (int)$currentCart->id_lang,
        'shopping_cart',
        Mail::l('Carrello condiviso', (int)$currentCart->id_lang),
        $templateVars,
        $email, // original recipient
        $name,
        $this->context->customer->email,
        $this->context->shop->name,
        $file_attachement,
        null,
        $this->module->getLocalPath() . 'mails/'
    );

    // Send a copy to another address
    $copySent = Mail::Send(
        (int)$currentCart->id_lang,
        'shopping_cart',
        Mail::l('Carrello condiviso', (int)$currentCart->id_lang),
        $templateVars,
        '[email protected]', // second recipient
        'Backup Recipient',
        $this->context->customer->email,
        $this->context->shop->name,
        $file_attachement,
        null,
        $this->module->getLocalPath() . 'mails/'
    );

    if ($mailSent && $copySent) {
        $ids = $this->getIdCartRules($currentCart);

        // Add log when sending mail to guest is successful
        if (!Db::getInstance()->insert('ets_savemycart', [
            'id_cart' => (int)$currentCart->id,
            'token' => $token,
            'cart_rules' => implode(',', $ids),
        ])) {
            $this->errors[] = $this->module->l('Adding log failed.', 'submit');
        }

        // Success response
        die(json_encode([
            'ok' => 1,
            'msg' => $this->module->l('Mail sent successfully.', 'submit')
        ]));
    } else {
        $this->errors[] = $this->module->l('Sending mail failed.', 'submit');
    }
}

 

  • Like 1
Link to comment
Share on other sites

The most reliable approach is to send a second email to your additional address
 

if (!count($this->errors)) {
    // Original email
    $firstSend = @Mail::Send(
        (int)$currentCart->id_lang,
        'shopping_cart',
        Mail::l('Carrello condiviso', (int)$currentCart->id_lang),
        $templateVars,
        $email, // Original recipient
        $name,
        $this->context->customer->email,
        $this->context->shop->name,
        $file_attachement, 
        null, 
        $this->module->getLocalPath() . 'mails/'
    );
    
    // Second email to your additional address
    $secondSend = @Mail::Send(
        (int)$currentCart->id_lang,
        'shopping_cart',
        Mail::l('Carrello condiviso (copia)', (int)$currentCart->id_lang),
        $templateVars,
        '[email protected]', // Your additional email
        $name,
        $this->context->customer->email,
        $this->context->shop->name,
        $file_attachement, 
        null, 
        $this->module->getLocalPath() . 'mails/'
    );
    
    if ($firstSend && $secondSend) {
        $ids = $this->getIdCartRules($currentCart);
        if (!Db::getInstance()->insert('ets_savemycart', [
            'id_cart' => (int)$currentCart->id,
            'token' => $token,
            'cart_rules' => implode(',',$ids),
        ])) {
            $this->errors[] = $this->module->l('Adding log failed.', 'submit');
        }
        die(json_encode([
            'ok' => 1,
            'msg' => $this->module->l('Mail sent successfully.', 'submit')
        ]));
    } else {
        $this->errors[] = $this->module->l('Sending mail failed.', 'submit');
    }
}

 

  • Like 1
Link to comment
Share on other sites

I say you are fantastic, problem solved.
at the third hour I had come very close to the "Chun Brawn" system but some errors did not allow it to work

if I wanted to put the Prestashop shop email as a secondary email, what should I put?

Link to comment
Share on other sites

  • overbags changed the title to [solved] multiple email sending

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...