Jump to content

How to add admin as "bcc" of all customers' order status emails ?


sailing123
 Share

Recommended Posts

Hi again :-)

Another issue that I need to address.

In Cubecart 4, the admin receives a copy of all emails sent to customers, ie pending, processing, complete, etc. This is great for 2 reasons:

  1. when the customer mistypes her/his email address, our email system alerts us and 50% of the time we can correct it manually and resend the emails so minimum communication interruption 
  2. remotely we can check that orders have been dispatched by members of staff without actually going into the admin. Although point 1 is more important.

In Cubecart 6, the store settings only let the admin choose one set of order status email only.

Al tells me that I could just edit the classes/mailer.class.php file to BCC me into ever send function call.

I had a quick look and it is all php coding, well above my capabilities. Would anyone know the coding bit I require and where to insert it please ?

Thanks

S.

Edited by sailing123
Link to comment
Share on other sites

The following is a plan to create two Code Snippets for CC615: one to "globalize" the Mailer class instance instantiated by Order->orderStatus(), and the other to toss in all admin emails that have been set to receive such notifications to a BCC array.

In admin, Manage Hooks, Code Snippets tab, click Add Snippet.

Enabled: Checked
Unique ID: [email protected]
Execution Order: 99
Description: Class-izes the Mailer instantiation so that it can be seen outside the orderStatus() method.
Trigger: class.order.order_status
Version: 1.0
Author: https://forums.cubecart.com/topic/52330-how-to-add-admin-as-bcc-of-all-customers-order-status-emails/
PHP Code:
<?php
$this->_mailer =& $mailer;

Save.

Start another Code Snippet.

Enabled: Checked
Unique ID: [email protected]
Execution Order: 99
Description: BCC's the admins on all customer emails.
Trigger: class.order.assign_order_details
Version: 1.0
Author: https://forums.cubecart.com/topic/52330-how-to-add-admin-as-bcc-of-all-customers-order-status-emails/
PHP Code:
<?php
//$this->_mailer->SMTPDebug = 2;
//$this->_mailer->Debugoutput = 'error_log';
$addBCC_notify_admins = explode(',', $this->_notifyAdmins());
foreach ($addBCC_notify_admins as $admin) {
$this->_mailer->addBCC($admin);
}

Save.

As I have been testing this, a couple of things are preventing me from discovering if this really works. I see the names getting added to the BCC array, and I see the names being mentioned in RCPT TO commands to the SMTP Server. But (due to a funny thing about my web server), the Test Gateway does not complete, so I do not get all the diagnostics I want, and maybe the SMTP server I am sending this out to is grouping all the email addresses (as the customer and all admins have the same domain of an email address). I do not see any BCC TO command.

So, more experimenting. But I wanted to get this posted.

 

Edited by bsmither
  • Like 1
Link to comment
Share on other sites

Hi bsmither,

Can't it be just a matter of letting the store settings to allow multiple selection in the function  "Order status for admin email notifications", using the html <select multiple> for the form ? You then hold down the Ctrl (windows) / Command (Mac) button to select multiple options, like this https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple

S.

 

Link to comment
Share on other sites

I tested your code snippet today with emails as a customer contacting us, with good results. One plugin email did not BCC, but it actually only emails the admin, anyway, to notify of a new testimonial waiting for approval. So I would think it's outside the logic of your snippet.

Going to test with some fake orders now.

No such luck on orders. I get a string of nonsense characters ( PD9waHAKJHRoaXMtPl9tYWlsZXIgPSYgJG1haWxlcjs= ) on a blank page when the snippets are enabled and I try to change from Pending to Processing on my fake order.

Quote

[19-Mar-2017 16:21:30 America/Chicago] PHP Fatal error:  Call to a member function addBCC() on null in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 6

 

Link to comment
Share on other sites

The snippet hooks into the CubeCart code that does things when an order's status changes. It is meant to BCC a copy of the customer's email that CubeCart sends when the order moves through the various statuses.

If a visitor uses the Contact Us page, this has nothing to do with moving an order to a different status. (You, as the admin, should be getting the email from the Contact Us page anyway!)

Link to comment
Share on other sites

I thought the idea was to get a BCC, so I could easily reply to the customer to any email the admin received.

I un-commented the debug lines in the snippet and tried Pending to Processing again. I still get the string of characters on a blank page, but there's more in the error log:

Quote

[19-Mar-2017 16:27:11 America/Chicago] PHP Fatal error:  Call to a member function addBCC() on null in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 6
[19-Mar-2017 16:35:07 America/Chicago] PHP Warning:  Creating default object from empty value in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 2
[19-Mar-2017 16:35:07 America/Chicago] PHP Fatal error:  Call to undefined method stdClass::addBCC() in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 6

 

 

Here's the snippet_3afa312cdc3acf2182d2144a8cfac7be.php as it reads now:

<?php
$this->_mailer->SMTPDebug = 2;
$this->_mailer->Debugoutput = 'error_log';
$addBCC_notify_admins = explode(',', $this->_notifyAdmins());
foreach ($addBCC_notify_admins as $admin) {
$this->_mailer->addBCC($admin);
}

 

Link to comment
Share on other sites

"Creating default object from empty value"

This tells me that the first snippet isn't getting executed. The snippet at class.order.order_status has this:

$this->_mailer =& $mailer;

This statement is what allows the second snippet to be able to call functions in the Mailer.

Are you moving a fake order via admin control? As opposed to working your way through a purchase from start to finish as a customer?

 

Link to comment
Share on other sites

The non-sense characters are the contents of the first snippet -- base64 encoded.

So, CubeCart must not have this snippet stored in the database correctly. But if so, then CubeCart must not be creating a snippet file from it.

You have snippet_3afa312cdc3acf2182d2144a8cfac7be.php, but where is snippet_5c6632328d5bb207a40e3ef624488c36.php?

Edited by bsmither
Link to comment
Share on other sites

Storing snippet code in the database in a base64 format is new to CC615.

But similar strange hash would appear on a blank page for any snippet code if the problem was with CubeCart code not decoding the snippet code properly.

So, I think the problem is (probably) not with Cubecart.

Link to comment
Share on other sites

Unless you have two stores using the same database? One at CC615 and the other at some other version ahead or behind, or some manual version edit to CC615 didn't make it from a version prior.

" That base64 encoded string is all that is in the other snippet. "

Where did you look? The snippet file or the CubeCart_code_snippet table?

If snippet_5c6632328d5bb207a40e3ef624488c36.php , then I assume the contents of snippet_3afa312cdc3acf2182d2144a8cfac7be.php are NOT base64 encoded?

Link to comment
Share on other sites

Ok, snippet_3afa is not encoded, but snippet_5c66 is encoded.

Try:

Delete the snippet_5c66.

Go back into admin, Code Snippets, bring up the first snippet ("Class-izes...") for editing. No need to edit it. Just save it.

CubeCart will not make another snippet until it is actually needed. So, make another test order. (Or maybe move an existing Processing order to Completed.)

 

Link to comment
Share on other sites

Sorry -

UEQ5d2FIQUtKSFJvYVhNdFBsOXRZV2xzWlhJZ1BTWWdKRzFoYVd4bGNqcz0=

[19-Mar-2017 17:43:47 America/Chicago] PHP Warning:  Creating default object from empty value in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 2
[19-Mar-2017 17:43:47 America/Chicago] PHP Fatal error:  Call to undefined method stdClass::addBCC() in /home/butter01/public_html/plushtest/includes/extra/snippet_3afa312cdc3acf2182d2144a8cfac7be.php on line 6

 

Maybe I copied something wrong when I created the snippets:

Went to see to make a copy of my code for you and found THIS!

Is THIS supposed to be in the snippet box where I saved the classize one?????

UEQ5d2FIQUtKSFJvYVhNdFBsOXRZV2xzWlhJZ1BTWWdKRzFoYVd4bGNqcz0=

Link to comment
Share on other sites

Ok, this:
UEQ5d2FIQUtKSFJvYVhNdFBsOXRZV2xzWlhJZ1BTWWdKRzFoYVd4bGNqcz0=

is base64 encoded this:
PD9waHAKJHRoaXMtPl9tYWlsZXIgPSYgJG1haWxlcjs=

You deleted the snippet_5c66 file, and CubeCart put it back.

When you brought up the snippet for editing, did the code look like the code in my initial post above?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...