Jump to content

Should order confirmation emails also be received by store?


alexm
 Share

Recommended Posts

Hey @kongondo should a copy of confirmation/invoice email be sent to the admin, as it doesn't appear to be working for us if so.

It could be that I believe you are sending emails as the "store email address" and if this email address is managed by a service provider like Google, sending from that email will be rejected by google as it will have come from the server. So it might be a good idea to have two fields. One for "store email" and one for "send emails from" so you can choose an email address that is managed by the local mail exchanger.

Just an idea as we don't seem to be receiving any confirmation emails at the moment, so don't notice when we are getting orders.

  • Like 1
Link to comment
Share on other sites

Hi @alexm,

Sir, that's a great suggestion! 

4 hours ago, alexm said:

It could be that I believe you are sending emails as the "store email address"

That's exactly it.

4 hours ago, alexm said:

So it might be a good idea to have to fields. One for "store email" and one for "send emails from" so you can choose an email address that is managed by the local mail exchanger.

Good idea. I'll have a think where to slot the extra email field in the GUI. Thanks.

Link to comment
Share on other sites

  • 2 months later...
26 minutes ago, Spinbox said:

@kongondo, how can we send a copy of a confirmation email to the store's email address?

Hi @Spinbox. This is coming in the next version (hopefully next week, there are quite a number of changes to it, so it is taking a bit of time). Meanwhile, do you mind using a Hook? I can show you how. Thanks.

  • Like 1
Link to comment
Share on other sites

Yo @kongondo 

How far off is the following code as an interim solution for mine and @Spinbox's requirements?

It doesn't seem to be working and I can't see what I'm missing.

(I've changed the actual domain to 'domain.com' and admin page name to '/processwire/' for posting here)

 

$this->addHookAfter('PadloperProcessOrder::sendConfirmation', null, 'sendOrderConfirmationToAdmin');

function sendOrderConfirmationToAdmin(HookEvent $event) {

  $object = $event->object;

  $orderPage = $event->arguments(0);

  if (is_null($orderPage)) {
    $orderPage = $object->getOrderPage();
  }

  if (empty($orderPage->id)) return;

  $orderId = $orderPage->id;

  // Drop this in place of $loginLink to send the request straight to the print order link
  // $printInvoiceUrl = "https://www.domain.com/processwire/shop/orders/print-invoice/?id=$orderId";

  $loginLink = "https://www.domain.com/processwire/shop/orders/view/?id=$orderId";

  $shopEmail = wire('padloper')->getShopEmail();
  $mail = wireMail();
  $mail->to("email@domain.com");
  $mail->from('no-reply@online.domain.com');
  $mailSubject = sprintf(__("New Order - #%s"), $orderId);
	$mail->subject($mailSubject);
  $mail->body("There's been a new order #$orderId!");
  $mail->bodyHTML("<p>There's been a new order #$orderId!</p><p><a href='$loginLink'>Click to login and view</a></p>");
  $mail->send();
}

 

  • Like 1
Link to comment
Share on other sites

On 6/23/2023 at 2:26 PM, alexm said:

It doesn't seem to be working and I can't see what I'm missing.

Hey @alexm,

Please clarify this. Does it mean the hook is not getting called or does it mean it is returning early (e.g. no $orderPage->id) or email not getting sent or email not getting received ?. If you did $sent = $mail->send(); and dumped $sent, what do you get back?

  • Like 1
Link to comment
Share on other sites

Haha, yeah, poor form on my part for not being at all descriptive. Sorry!

 The hook is called for sure

I'm uncertain as to the rest. If I do a bar dump on $sent = $mail->send(); I get 1 as the response. I don't know whether this would be the expected response mind and there is definitely no email being received. So somewhere around this point there seems to be a potential issue. I'm receiving emails from the email address being set as the from address in other parts of the code which utilises wireMail(), which is why I thought perhaps my hook's function wasn't quite set up right. Though it seems like it should be to me...

  • Like 1
Link to comment
Share on other sites

7 hours ago, alexm said:

If I do a bar dump on $sent = $mail->send(); I get 1 as the response. I don't know whether this would be the expected response

1 means that $mail sent 1 message. So, we know that that succeeded. Hmm. I am at a loss about this one. Given that the hook is called an an email is sent, I have no reason to suspect that the hook is perhaps being called late.

  1. Do you know if the customer is getting the email being sent by Padloper for this same order?
  2. Secondly, just for testing could you please test with Hooking before?
  3. Are you able to please test the exact same Hook function but by hooking to another method, e.g. ___saveOrder()?

Thanks.

  • Like 1
Link to comment
Share on other sites

Ok weirdest vibe!! I've just received 2 emails for orders (2 new live orders) with the above code and no changes. One being a stripe payment and one being a paypal payment. I wonder whether that narrows it down to me using Invoice payment as the option. Either way, it's working as expected.

How very very bizarre!!

  • Like 1
Link to comment
Share on other sites

On 6/26/2023 at 6:54 PM, alexm said:

How very very bizarre!!

Very!

I have tested your code (verbatim) with both Stripe and Invoice payments and emails are sent in both cases! Maybe your first one (Invoice) ended up in the ether? I am assuming you checked your junk folder.

  • 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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...