× This forum has been locked. Please submit new Feature Requests on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues

adding send email function to backend

7 años 7 meses antes #1433 por Marcin
It would be nice to have send email function added to edit, create new - buttons on backed.

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

7 años 3 meses antes #1466 por Ruud van Lent
Respuesta de Ruud van Lent sobre el tema adding send email function to backend
Hi,

just added this to the front-end form. When a new item is created and saved (via the controllers save function), the following function is called that will send an email to all users that have in their profile 'Receive system emails' set to yes.

hope this helps.
regards,
Ruud
/**
	 * Send mail to administrators
	 *
	 * @param   integer  $id  The id of the row to check out.
	 *
	 * @return void
	 */
	public function sendSystemMail($id)
	{
		// Get the id.
		$id = (!empty($id)) ? $id : (int) $this->getState('newsitem.id');

		$app = JFactory::getApplication('com_ochgotnews');
		$params = $app->getParams();

		if ($params->get('ochgotnews_mailonnew', true))
		{
			$user = JFactory::getUser();

			// Build the email subject and message
			$sitename = JFactory::getApplication()->get('sitename');
			$siteURL = JUri::root() . 'administrator/index.php?option=com_ochgotnews&task=newsitem.edit&id=' . $id;
			$subject = JText::sprintf('COM_OCHGOTNEWS_MAIL_SUBJECT', $sitename);
			$msg = JText::sprintf('COM_OCHGOTNEWS_MAIL_MESSAGE', $siteURL);

			// Get the user that are configured to receive system emails
			$db = JFactory::getDBO();
			$query = $db->getQuery(true);
			$query
				->select(array('name', 'email'))
				->from($db->quoteName('#__users'))
				->where($db->quotename('sendEmail') . ' = ' . $db->quote('1'));
			$db->setQuery($query);
			$recipients = $db->loadObjectList();

			foreach ($recipients as $recipient)
			{
				// Compile mailer function:
				$mailer = JFactory::getMailer()
				->setSubject($subject)
				->setBody($msg)
				->setSender(
					$user->email,
					$user->name
					)
				->addRecipient(
					$recipient->email,
					$recipient->name
					);

				$mailer->Send();
			}
		}
	}

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Tiempo de carga de la página: 0.124 segundos
Gracias a Foro Kunena

Utilizamos cookies propias y de terceros para mejorar nuestros servicios y mostrarle publicidad relacionada con sus preferencias mediante el análisis de sus hábitos de navegación. Si continua navegando, consideramos que acepta su uso.