CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Send email hook
Pages: [1]

Author Topic: Send email hook  (Read 998 times)

darkchild

  • I post occasionally
  • **
  • Posts: 33
  • Karma: 2
  • “…more than kisses, letters mingle souls…”- John D
  • CiviCRM version: 4.0.1
  • CMS version: joomla & drupal
  • MySQL version: 5.0.91
  • PHP version: 5.2.14
Send email hook
January 08, 2012, 09:05:03 pm
Has anyone been able to get this to work on Joomla? Been trying to get this to work on Joomla 1.7.3/civi 4 without success

Code: [Select]
function joomla_civicrm_post($op, $objectName, $objectId, &$objectRef) {

  /**************************************************************
   * Send an email when Individual Contact is CREATED or EDITED or DELETED
   */
  $send_an_email = false; //Set to TRUE for DEBUG only
  $email_to = 'me@gmail.com'; //TO email address
  $email_from = 'info@me.org'; //FROM email address
  $email_sbj = 'CiviCRM exampleSendEmailOnIndividual';
  $email_msg = "CiviCRM exampleSendEmailOnIndividual was called.\n".$op." ".$objectName."\n".$objectId." ";

  if ($op == 'create' && $objectName == 'Individual') {
    $email_sbj .= "- ADDED NEW contact";
    $email_msg .= $objectRef->display_name."\n";
    $send_an_email = true;
  } else if ($op == 'edit' && $objectName == 'Individual') {
    $email_sbj .= "- EDITED contact";
    $email_msg .= $objectRef->display_name."\n";
    $send_an_email = true;
  } else if ($op == 'delete' && $objectName == 'Individual') {
    $email_sbj .= "- DELETED contact";
    $email_msg .= $objectRef->display_name."\n";
    $email_msg .= 'Phone: '.$objectRef->phone."\n";
    $email_msg .= 'Email: '.$objectRef->email."\n";
    $send_an_email = true;
  }

  if ($send_an_email) {
    mail($email_to, $email_sbj, $email_msg, "From: ".$email_from);
  }

}


I got the code from the Documentation

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Send email hook
January 09, 2012, 05:24:16 am
Hi,

In drupal, you need to change the name of the function so it matches the name of your module, pretty sure it's the same in joomla

This chapter should help you getting started:
http://book.civicrm.org/developer/techniques/hooks

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Send email hook
January 09, 2012, 08:43:37 am
For joomla you need to implement a plugin, check http://civicrm.org/blogs/mcsmom/hooks-and-joomla

Hth
Kurund
Found this reply helpful? Support CiviCRM

darkchild

  • I post occasionally
  • **
  • Posts: 33
  • Karma: 2
  • “…more than kisses, letters mingle souls…”- John D
  • CiviCRM version: 4.0.1
  • CMS version: joomla & drupal
  • MySQL version: 5.0.91
  • PHP version: 5.2.14
Re: Send email hook
January 09, 2012, 01:44:17 pm
I have tried both the plugin and placing a civicrm hooks file in the custom php gfolder. None of theme work....

Here is the plugin code used...
Code: [Select]
<?php

/**
* @version
* @package Civicrm
* @subpackage Joomla Plugin
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// No direct access

defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');

class 
plgCivicrmHooks extends JPlugin

{

/**

  * Example Civicrm Plugin

  * @package Civicrm

  * Joomla plugins
  * @since 1.5
  */

public function civicrm_post($op, $objectName, $objectId, &$objectRef) {

  
/**************************************************************
   * Send an email when Individual Contact is CREATED or EDITED or DELETED
   */
  
$send_an_email = false; //Set to TRUE for DEBUG only
  
$email_to = 'me@me.com'; //TO email address
  
$email_from = 'ime@me.com'; //FROM email address
  
$email_sbj = 'CiviCRM exampleSendEmailOnIndividual';
  
$email_msg = "CiviCRM exampleSendEmailOnIndividual was called.\n".$op." ".$objectName."\n".$objectId." ";

  if (
$op == 'create' && $objectName == 'Individual') {
    
$email_sbj .= "- ADDED NEW contact";
    
$email_msg .= $objectRef->display_name."\n";
    
$send_an_email = true;
  } else if (
$op == 'edit' && $objectName == 'Individual') {
    
$email_sbj .= "- EDITED contact";
    
$email_msg .= $objectRef->display_name."\n";
    
$send_an_email = true;
  } else if (
$op == 'delete' && $objectName == 'Individual') {
    
$email_sbj .= "- DELETED contact";
    
$email_msg .= $objectRef->display_name."\n";
    
$email_msg .= 'Phone: '.$objectRef->phone."\n";
    
$email_msg .= 'Email: '.$objectRef->email."\n";
    
$send_an_email = true;
  }

  if (
$send_an_email) {
    
mail($email_to, $email_sbj, $email_msg, "From: ".$email_from);
  }

}
The name of the plugin is Hooks and created  the xml file and then were no errors  in installation.

Rajesh

  • I post occasionally
  • **
  • Posts: 78
  • Karma: 10
  • CiviCRM version: 4.2.x, 4.3.x, 4.4.x
  • CMS version: Drupal 7.xx, Wordpress 3.5.x - 3.6.x, Joomla 3.1
  • MySQL version: 5.5.20
  • PHP version: 5.3.10
Re: Send email hook
January 11, 2012, 02:11:43 am
Hi

I have done a simple joomla plugin to implement hook_civicrm_contactListQuery. Download the plugin zip file http://dl.dropbox.com/u/34943170/plg_civicrm_base.zip

To install the plugin, navigate to Extension Manager >> Install. In Upload Package File, upload the zip file and install.

Hope this helps.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Send email hook

This forum was archived on 2017-11-26.