Results 1 to 10 of 10

Thread: If statement, variables in InbounEmail.php

  1. #1
    cefladental's Avatar
    cefladental is offline Sugar Community Member
    Join Date
    Jan 2010
    Location
    Charlotte, NC
    Posts
    51

    Question If statement, variables in InbounEmail.php

    Hopefully someone has an answer for me on this.

    I added the following code with the hopes that the case type would change depending on the "sent to" address. For examply, any email that was sent to support@myurl.com would be set to Support, anything sent to marketing@myurl.com would be set to Marketing, etc.

    Anyway, here is what I added to get started:

    Code:
    $reply->to_addrs            = $sentto;
    Code:
    if ($sentto == 'administrator@ceflaamerica.com') { 
                    $type = 'Voicemail'; 
                } else {
                    $type = 'Support'; 
                }
    Code:
    $c->type = $type;
    The if statement does work, however, all cases are set to case type of Support. Any ideas?
    Brett Power

  2. #2
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: If statement, variables in InbounEmail.php

    Are you sure with the first row of your code? Is '$sentto' filled with 'administrator@ceflaamerica.com' in some cases?
    Stefan Ulrich Sauer
    System Analyst

    Devoteam Danet GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.de

  3. #3
    cefladental's Avatar
    cefladental is offline Sugar Community Member
    Join Date
    Jan 2010
    Location
    Charlotte, NC
    Posts
    51

    Default Re: If statement, variables in InbounEmail.php

    The first line is simply saying that if the address that the Email was sent to is equal to the address listed, the Type will be set to "Voicemail", otherwise it should be set to "Support". The problem is I don't think the variable "$sentto" is actually working.
    Brett Power

  4. #4
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: If statement, variables in InbounEmail.php

    I didn't ask for the if-statement but for this row:
    PHP Code:
    $reply->to_addrs            $sentto
    Stefan Ulrich Sauer
    System Analyst

    Devoteam Danet GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.de

  5. #5
    cefladental's Avatar
    cefladental is offline Sugar Community Member
    Join Date
    Jan 2010
    Location
    Charlotte, NC
    Posts
    51

    Default Re: If statement, variables in InbounEmail.php

    Yes, in some cases that variable does equal the mentioned email address.
    Brett Power

  6. #6
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: If statement, variables in InbounEmail.php

    In my 6.0.1 and 6.2.0beta installations there is no variable $sentto in InboundEmail.php .
    Could you post the complete function you've changed?
    Stefan Ulrich Sauer
    System Analyst

    Devoteam Danet GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.de

  7. #7
    cefladental's Avatar
    cefladental is offline Sugar Community Member
    Join Date
    Jan 2010
    Location
    Charlotte, NC
    Posts
    51

    Default Re: If statement, variables in InbounEmail.php

    Here is the whole bit of code:

    Code:
    $et = new EmailTemplate();
                    $et->retrieve($this->template_id);
                    if(empty($et->subject))        { $et->subject = ''; }
                    if(empty($et->body))        { $et->body = ''; }
                    if(empty($et->body_html))    { $et->body_html = ''; }
    
                    $reply = new Email();
                    $reply->type                = 'out';
                    $reply->to_addrs            = $to[0]['email'];
                    $reply->to_addrs            = $sentto;
                    $reply->to_addrs_arr        = $to;
                    $reply->cc_addrs_arr        = array();
                    $reply->bcc_addrs_arr        = array();
                    $reply->from_name            = $from_name;
                    $reply->from_addr            = $from_addr;
                    $reply->name                = $et->subject;
                    $reply->description            = $et->body;
                    $reply->description_html    = $et->body_html;
                    $reply->reply_to_name        = $replyToName;
                    $reply->reply_to_addr        = $replyToAddr;
    Brett Power

  8. #8
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: If statement, variables in InbounEmail.php

    Sorry, I can't help you if you just give me pieces of your code ... That is not the whole function.

    I need at least this:
    PHP Code:
    function <name> ( <params>)
    {
    <
    all the code of that function including all the changes you made>

    I'd like to see where your $sentto parameter is coming from to get an idea why the if statement you mentioned is not working as expected.
    Stefan Ulrich Sauer
    System Analyst

    Devoteam Danet GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.de

  9. #9
    cefladental's Avatar
    cefladental is offline Sugar Community Member
    Join Date
    Jan 2010
    Location
    Charlotte, NC
    Posts
    51

    Default Re: If statement, variables in InbounEmail.php

    All fixed!

    I had the wrong variable from the beginning.

    The variable that represents the address that the Email was sent to is:

    Code:
    $email->to_addrs
    After finding that i added this if statement:

    Code:
    if ($email->to_addrs  == "support@xxx.com") { 
                    $type = 'Support'; 
                } else {
                    $type = 'Voicemail'; 
                }
    
    		$c = new aCase();
    		$this->getCaseIdFromCaseNumber($email->name, $c);
    
    		if (!$this->handleCaseAssignment($email) && $this->isMailBoxTypeCreateCase()) {
    			// create a case
    			$GLOBALS['log']->debug('retrieveing email');
    			$email->retrieve($email->id);
    			$c = new aCase();
    			$c->description = $email->description;
    			$c->assigned_user_id = $userId;
    			$c->name = $email->name;
    			$c->status = 'New';
    			$c->type = $type;
    			$c->account_id = '2ed3443c-62b2-798d-fab2-4b4ead46df31';
    			$c->priority = 'P1';
    
    			if(!empty($email->reply_to_email)) {
    				$contactAddr = $email->reply_to_email;
    			} else {
    				$contactAddr = $email->from_addr;
    			}
    Brett Power

  10. #10
    cefladental's Avatar
    cefladental is offline Sugar Community Member
    Join Date
    Jan 2010
    Location
    Charlotte, NC
    Posts
    51

    Default Re: If statement, variables in InbounEmail.php

    To help anyone else out with this functionality, I was able to make it even more flexible with a few "elseif" lines as well. Now, no matter what email address the messages go to they will have the correct "type" set when the case is created. That way we can tell which is which and handle/sort them easier once in Sugar.

    Code:
    if ($email->to_addrs  == "support@xxx.com") { 
                    $type = 'Support'; 
                } 
    elseif ($email->to_addrs  == "messages@xxx.com") { 
                    $type = 'Voicemail'; 
                } 
    elseif ($email->to_addrs  == "offline.support@xxx.com") { 
    			$type = 'Offline Support';
    		  } else {
    			$type = 'Administration';
    		  }
    Brett Power

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. if statement in logic hook
    By japtone in forum Developer Help
    Replies: 2
    Last Post: 2011-03-02, 12:21 AM
  2. Need help with a SQL statement
    By chrislynch8 in forum Help
    Replies: 1
    Last Post: 2010-11-11, 04:21 PM
  3. Help with a SQL statement
    By Iggby in forum Developer Help
    Replies: 2
    Last Post: 2009-03-31, 03:24 PM
  4. Join or IF Statement??
    By gkeyes in forum Help
    Replies: 3
    Last Post: 2008-05-22, 05:40 PM

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
  •