*

Osclass2024

  • **
  • 15 posts
Hello, how can I send email to all registered users when a user publishes a new article or updates it?

*

MB Themes

Re: Send email to all registered users when publishing a new article
« Reply #1 on: March 29, 2024, 01:19:50 PM »
Sounds like spammy idea that could survive few days :)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Osclass2024

  • **
  • 15 posts
Re: Send email to all registered users when publishing a new article
« Reply #2 on: March 29, 2024, 04:53:12 PM »
It may sound like spam, but in reality we have osclass running in a company, only employees can enter on an intranet, and only they can publish classified ads, but there are times where employees do not publish an ad for weeks, so when it is not published So often users lose interest in entering the classifieds site, so this would help so that when there is a new classified ad, employees are aware, and if they are interested they enter the site.

*

Osclass2024

  • **
  • 15 posts
Re: Send email to all registered users when publishing a new article
« Reply #3 on: April 03, 2024, 08:13:29 PM »
Well, I provide the solution, for those who may need it one day.

Look for the functions.php file of the sigma theme, and paste the following at the end before closing the php code:

Code: [Select]
if (!function_exists('usr_published_sent_email')) {
    function usr_published_sent_email($item) {
        if (osc_is_web_user_logged_in() && is_array($item)) {
            $user = User::newInstance()->findByPrimaryKey(osc_logged_user_id());
            View::newInstance()->_exportVariableToView('item', $item);

            // Array con correos electrónicos y nombres
$usuarios = User::newInstance()->listAll();

            // Iterar sobre los correos electrónicos y nombres del array
            foreach ($usuarios as $usuario) {
              if ($usuario['b_active']){
                $email = $usuario['s_email'];
                $name = $usuario['s_name'];
                $title = 'Nuevo Articulo Publicado!';

                $body =  'Hola ' . $name . ',<br>';
                $body .= '<br>';
                $body .= 'El usuario: <b>' . $user['s_name'] . '</b> realizo una nueva publicación<br>' . 'Para ver la publicacion del articulo "' . $item["s_title"] . '" Hace clic en: <br><br>';
                $body .= '<a href="' . osc_item_url() . '">' . osc_item_url() . '</a><br>';
                $body .= '<br>';
                $body .= 'Saludos<br>';
                $body .= '<br>';
                $body .= osc_esc_html(osc_page_title()) . '<br><br>';

                $emailParams = array(
                    'subject'  => $title,
                    'to'       => $email,
                    'to_name'  => $name,
                    'body'     => $body,
                    'alt_body' => $body
                );

                osc_sendMail($emailParams);
              }
            }
        }
    }
    osc_add_hook('posted_item', 'usr_published_sent_email');
}

*

MB Themes

Re: Send email to all registered users when publishing a new article
« Reply #4 on: April 05, 2024, 03:24:22 PM »
Hmm..

You should have condition $usuario['b_active'] == 1
Consider adding some timeout too (sleep) after each email is sent.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Osclass2024

  • **
  • 15 posts
Re: Send email to all registered users when publishing a new article
« Reply #5 on: April 10, 2024, 02:18:23 PM »
Hi MB Themes, I understood that in php comparing a 1 or a true in this case was the same

This is how I compare the code that had been passed previously.


           
Code: [Select]
foreach ($usuarios as $usuario) {
              if ($usuario['b_active']){

how to add a sleep?
« Last Edit: April 10, 2024, 02:20:34 PM by Osclass2024 »

*

MB Themes

Re: Send email to all registered users when publishing a new article
« Reply #6 on: April 12, 2024, 08:54:16 PM »
sleep(1)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots