Jump to content

Recommended Posts

Posted

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();

});

 

Posted

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();

});

 

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

Posted
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!

  • Haha 1

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
  • Recently Browsing   0 members

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