Results 1 to 5 of 5

Thread: Logic hook - send email

  1. #1
    jmfernandes is offline Junior Member
    Join Date
    Sep 2010
    Posts
    4

    Default Logic hook - send email

    Hi,

    I've being seing lots of discussions at the forum regarding a logic hook to send emails after_save. I've tried some codes however always got error messages from sugar. Than I came up with the following code, and didnt get any error messages, however nothing happened either (or I didnt receive the test email).

    Logic hook code (in my module's logic_hook.php)
    Code:
    $hook_array['before_save'] = array();
    		$hook_array['before_save'][] = array(1, 'notify_user', 'custom/modules/custom_module/notify_user.php', 'notify_user', 'notify_user');
    in my notify_user.php
    Code:
    <?php
    
    	if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    
    	class notify_user{
    
    		function notify_user(&$bean, $event, $arguments){
    require_once("include/SugarPHPMailer.php"); 
    $note_msg=new SugarPHPMailer(); 
                $admin = new Administration(); 
                 $admin->retrieveSettings(); 
    
    			
                $note_msg->Subject = 'Note: ' . $bean->name; 
                $note_msg->prepForOutbound(); 
                $note_msg->setMailerForSystem(); 
                $note_msg->Body = $bean->description; 
                $note_msg->From     = $admin->settings['notify_fromaddress']; 
                $note_msg->FromName = $admin->settings['notify_fromname'];  
                       
                $note_msg->To = 'email@company.com';
    if (!$note_msg->Send()) 
    
    			{
    										$GLOBALS['log']->info("Could not send case closed notification:  " . $mail->ErrorInfo);
    				
    			}
    		}
    	}
    
    ?>

    Can anyone tell me why my test code is not working and help me to personalize the code to:
    1) Send email to a specific user after a new record is created
    2) Send email to assignee user after the record is modified

    tks
    JM
    Last edited by jmfernandes; 2010-10-08 at 06:01 AM.

  2. #2
    davidboris is offline Sugar Community Member
    Join Date
    May 2010
    Posts
    1,113

    Default Re: Logic hook - send email

    Hello,

    Change line from

    PHP Code:
    $note_msg->To 'email@company.com'
    to
    PHP Code:
    $note_msg->AddAddress('EMAIL_ADDRESS'); 
    Thumbs up.

    Skype ID - david__boris

    SugarForge Projects:

    WYSIWYG now in studio!(Version 1.1 is out now!)

    Sugar Feeds on your personalized home pages like iGoogle, My Yahoo!, etc.

    Fab Tools! > Dashlet Not Followed Opportunities for past six Months

  3. #3
    jmfernandes is offline Junior Member
    Join Date
    Sep 2010
    Posts
    4

    Default Re: Logic hook - send email

    Tks David it worked fine !

    Do you know how do I do to personalize this code to :
    1) Send email only when the record is created
    2) Send this email only when the record is modified, I have to send this modification note to the assigned user.

    Tks a lot for helping !!!

  4. #4
    davidboris is offline Sugar Community Member
    Join Date
    May 2010
    Posts
    1,113

    Default Re: Logic hook - send email

    Hello,

    Sugar provides a facility to send notification to assigned user. Admin > Email Settings > Send notification on assignment. Which means, when you create a new record Sugar sends a notification.

    Now you want to send email when it is modified. You can write before_save logic hook and check if $bean->id is not null (which means it is getting modified) and so you send email again.
    Thumbs up.

    Skype ID - david__boris

    SugarForge Projects:

    WYSIWYG now in studio!(Version 1.1 is out now!)

    Sugar Feeds on your personalized home pages like iGoogle, My Yahoo!, etc.

    Fab Tools! > Dashlet Not Followed Opportunities for past six Months

  5. #5
    blablaz is offline Senior Member
    Join Date
    Jan 2011
    Posts
    25

    Default Re: Logic hook - send email

    Hello everyone,

    I have quite a big issue with sending email through logic_hooks.
    I'm currently using SugarCRM 6.1.3 , in a Windows 7 OS.

    What i need to do is to send a calendar entry by email, to my attendies, so that they can use this email to create the entry in their Outlook, Zimbra, iCal or Gmail calendars.
    In the following example i am just trying to send it to one email address.

    I created a logic_hook before_save in ../custom/modules/Meetings/logic_hooks.php
    PHP Code:
    <?php
    // Do not store anything in this file that is not part of the array or the hook version.  This file will    
    // be automatically rebuilt in the future. 
    $hook_version 1
    $hook_array = Array(); 
    // position, file, function 
    $hook_array['before_save'] = Array(); 
    $hook_array['before_save'][] = Array(1'meeting invitation''custom/modules/Meetings/sendEmailMeeting.php','SendMail''createMail'); 
    ?>
    And here is the file ../custom/modules/Meetings/sendEmailMeeting.php:

    PHP Code:
    <?php 

    class SendMail {
       
        function 
    createMail($bean$event$arguments){
        
        require_once(
    "include/SugarPHPMailer.php");
        
        
    $location$this->bean->location;

        
    $headers "From: SugarCRM <myaddress@mycompany.com>\n";
        
    $headers .= "MIME-Version: 1.0\n";
        
    $headers .= "Content-Type: text/calendar; method=REQUEST;\n";
        
    $headers .= '        charset="UTF-8"';
        
    $headers .= "\n";
        
    $headers .= "Content-Transfer-Encoding: 7bit\n";

        
    $subject $this->bean->name;
        
    $subject html_entity_decode($subjectENT_QUOTES'UTF-8');
        
        
    $message"BEGIN:VCALENDAR
        VERSION:2.0
        CALSCALE:GREGORIAN
        METHOD:REQUEST
        BEGIN:VEVENT
        DTSTART:20110616T080000Z   
        DTEND:20110616T090000Z
        DTSTAMP:20110616T075116Z
        ORGANIZER;CN=SugarCRM:mailto:some.body@mycomp.com
        UID:1
        ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Sample:mailto:sample@test.com
        DESCRIPTION:Complete event on http://www.sample.com/get_event.php?id=1
        LOCATION: $location
        SEQUENCE:0
        STATUS:CONFIRMED
        SUMMARY:Test iCalendar
        TRANSP:OPAQUE
        END:VEVENT
        END:VCALENDAR"
    ;
        
        
        
    mail("mytarget@somecompany.com"$subject$message$headers);  
        
        
        }
    }
    ?>
    Any help will be much appreciated
    Thanks in advance!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Send email via logic hook
    By mahe11 in forum Developer Help
    Replies: 0
    Last Post: 2010-08-06, 03:32 PM
  2. email logic hook
    By cs3gallery in forum Developer Help
    Replies: 12
    Last Post: 2010-06-11, 03:20 PM
  3. Logic hook to send email with attachments
    By kinshibuya in forum Developer Help
    Replies: 3
    Last Post: 2009-10-21, 05:53 PM
  4. Need Help Creating logic hook to send data to external app
    By amymicheals in forum Developer Help
    Replies: 5
    Last Post: 2009-07-21, 11:02 AM
  5. want to send email in logic hook
    By akkimca in forum Developer Help
    Replies: 1
    Last Post: 2009-04-02, 07:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •