fuzendesign Posted November 13, 2021 Posted November 13, 2021 I want to send an email when a page is published or updated. Specifically a template (temp_order_detail). For now, I just want to get the page-update code working. Why does the following code not send an email? I’ve tried using a from address of both my PW admin address and one tied to the domain the site resides on. Neither addresses work. Is there a whitelist in Processwire for valid emails to send from? I have this code in site > ready.php file: wire()->addHookAfter('Pages(template=temp_order_detail)::published', function(HookEvent $event) { // Get the object the event occurred on, if needed $pages = $event->object; // Get values of arguments sent to hook (if needed) $page = $event->arguments(0); // your code: $page = $event->arguments[0]; $mail->new(); $mail->subject("Your order ".$page->title."has been submitted..."); $mail->to("testemail@gmail.com"); $mail->from("emailaccount@mydomain.com"); $mail = bodyHTML("<html><body><p>Your delivery order has been created.</p><p>Blah blah blah ".$page->title."</p></body></html>"); $mail->send(); });
wbmnfktr Posted November 13, 2021 Posted November 13, 2021 Are you sure that's valid (marked in bold)? wire()->addHookAfter('Pages(template=temp_order_detail)::published', function(HookEvent $event) { // } I go with: wire()->addHookAfter('Page::published', function(HookEvent $event) { // } See here: https://github.com/processwire/processwire/blob/d78276e2c265f6b70384a13eb4febd4811a1db77/wire/core/Pages.php#L2197
fuzendesign Posted November 13, 2021 Author Posted November 13, 2021 Assuming I go with your code, just to test and using PW docs code—without specifying a template—my email still doesn’t fire on even the most basic example: (My understanding is that this should fire on any page being published on the site. I want to narrow it down to just a specific template, but reducing things to the most basic, can’t figure why this won't work…and yes, I tried various combinations of this code and other for the last few hours.) wire()->addHookAfter('Page::published', function(HookEvent $event) { // Get the object the event occurred on, if needed $pages = $event->object; // Get values of arguments sent to hook (if needed) $page = $event->arguments(0); // your code: $page = $event->arguments[0]; $message = $mail->new(); $message->subject('Hello world') ->to('externalemail@gmail.com') ->from('email@mysitedomain.com') ->body('Hello there big world') ->bodyHTML('<h2>Hello there big world</h2>'); $numSent = $message->send(); });
fuzendesign Posted November 13, 2021 Author Posted November 13, 2021 22 minutes ago, wbmnfktr said: Are you sure that's valid (marked in bold)? wire()->addHookAfter('Pages(template=temp_order_detail)::published', function(HookEvent $event) { // } I could have sworn I grabbed that from code Ryan or an experienced developer here had use in answering someone’s question.
fuzendesign Posted November 14, 2021 Author Posted November 14, 2021 4 hours ago, bernhard said: See the last post in that thread ? @bernhard you are a gem in this community. I knew I had ran across that code from a trusted source. Anyways, somehow everything seems to be working fine this morning. Love it and thanks! 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now