Email_Sending: Matching more than one if

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
mpol_ch
User
Posts: 877
Location: Switzerland

Email_Sending: Matching more than one if

Post by mpol_ch »

Hi,
I am trying to send email after updating.
I am using if condition to check the three fields and I have two if condition matsching for one update.
It seems that the phpmaker is just sending email for one condition and stop to work.
How can I send email for each conditions?

 Example for table Cases

 Status: New
 Prio: Important
Anonym:  Yes 

 if ((CurrentPageID() == "edit") && ($args["rsnew"]["Status"] == "New"))
 $email->Recipient =  mail1@xxx.com;

 if ((CurrentPageID() == "edit") || ($args["rsnew"]["Prio"] == "Importatant"  && $args["rsnew"]["Anonym"] == "Yes" ))
$email->Recipient =  20maila@xxx.com;

 if ((CurrentPageID() == "edit") || ($args["rsnew"]["Status"] == "New"  && $args["rsnew"]["Anonym"] == "Yes" ))
$email->Recipient =  anona@xxx.com;

In this case all the 3 emails should get different email.
But right now just one email is being sent.

What should I do so that the system can sent more than one mail for all the matched if conditions?

mpol_ch


scs
User
Posts: 694

Post by scs »

$email->Recipient get updated if condition matched.

At the end, $email->Recipient will have the latest assigned value.


mpol_ch
User
Posts: 877
Location: Switzerland

Post by mpol_ch »

Hi,

what will happen if the condition 1 and also condition 2 match.
Will it send two times email?
Or it will send only email for the last matched condition?
mpol_ch


yusufnalbantoglu
User
Posts: 12

Post by yusufnalbantoglu »

Hi,

What you missed in the condition structure is that you should add the code "return false" to stop sending mail outside of the conditions.

if (CurrentPageID() == "edit") { 

if ($args["rsnew"]["Status"] != $args["rsold"]["Status"] && $args["rsnew"]["Status"] == "New") {
 
$email->Recipient = "mail1@xxx.com";

 } elseif ($args["rsnew"]["Prio"] != $args["rsold"]["Prio"] && $args["rsnew"]["Prio"] == "Important") ||  ($args["rsnew"]["Anonym"] != $args["rsold"]["Anonym"] && $args["rsnew"]["Anonym"] == "Yes") {
$email->Recipient = "20maila@xxx.com";
        }
        else { 
            return false; 
        } 
    }

mpol_ch
User
Posts: 877
Location: Switzerland

Post by mpol_ch »

Hi,
unfortuantely it does not help.
Plese keep in mind that I have two conditions which are match for "edit".
I want that the system send two email for both conditions.
I am not sure if this is possible ot if I shoud do a loop.

Second:
When I change a field let me say "notifications" which is not given in conditions then the system should not send any email.
It should send only if the conditions fields are changed.

mpol_ch


mpol_ch
User
Posts: 877
Location: Switzerland

Post by mpol_ch »

Here is my code.
Please keep in mind that for the edit more then one if could be true and the system should send for each if an email.

 // Email Sending event
 function Email_Sending($email, &$args)
{

   $FStatus=ExecuteScalar("SELECT Status FROM falle_status WHERE Id =".$this->Status->CurrentValue);
   $FNextStatus=ExecuteScalar("SELECT Next FROM falle_status WHERE Id =".$this->Status->CurrentValue);     
   $Gerichtsschreiber= ExecuteScalar("SELECT Mailu FROM mitarbeiter WHERE KZeichen ='". $this->Gs->CurrentValue."'");
   $Vorsitz=ExecuteScalar("SELECT Mailu FROM mitarbeiter WHERE KZeichen ='". $this->Vs->CurrentValue."'");
   $Kanzlei=ExecuteScalar("SELECT Mailu FROM mitarbeiter WHERE KZeichen ='". $this->Ka->CurrentValue."'");
   $Ausfertigung = ExecuteScalar("SELECT Name FROM bearbeiter WHERE Emailb ='". $this->Bearbeiter->CurrentValue."'");
   //var_dump($email, $args); exit();

   // Send Email to Gerichtsschreiber und Vorsitz
   if (CurrentPageID() == "add"){
    if ($this->Status->CurrentValue  == 1) { // If Add page
    $email->Cc = $Vorsitz;
    $email->Subject = "1In Sachen " .$args["rsnew"]["GNr"]; // Change subject
    $email->Content = "<p>Fall mit GNr: ".$args["rsnew"]["GNr"]. " zwischen den Parteien " .$args["rsnew"]["Parteien"]. " wurde aktualisiert</p>"; // Append additional content
    $email->Content .= "<p>VS: ".$args["rsnew"]["Vs"]. " Gs: " .$args["rsnew"]["Gs"]."</p>"; // Append additional content
    $email->Content .= "<p>Ausfertigung: ".$Ausfertigung."</p>";
    $email->Content .= "<p>Priorität: ".$args["rsnew"]["Prio"]. "</p>"; // Append additional content
    $email->Content .= "<p>Status: " .$FStatus. "</p>"; // Append additional content
    $email->Content .= "<p>NextStatus: " .$FNextStatus. "</p>"; // Append additional content
      } 
} 

   // Send Email to Gerichtsschreiber    
    if (CurrentPageID() == "edit"){
     if(($args["rsnew"]["Status"]  == 2) OR ($args["rsnew"]["Status"]  == 4) OR ($args["rsnew"]["Status"]  == 6) OR ($args["rsnew"]["Status"]  == 7)) { // If Add page
       $email->Recipient =  $Gerichtsschreiber;
       $email->Subject = "2In Sachen " .$args["rsnew"]["GNr"]; // Change subject
      $email->Content = "<p>Fall mit GNr: ".$args["rsnew"]["GNr"]. " zwischen den Parteien " .$args["rsnew"]["Parteien"]. " wurde aktualisiert</p>"; // Append additional content
     $email->Content .= "<p>VS: ".$args["rsnew"]["Vs"]. " Gs: " .$args["rsnew"]["Gs"]."</p>"; // Append additional content
     $email->Content .= "<p>Ausfertigung: ".$Ausfertigung."</p>";
    $email->Content .= "<p>Priorität: ".$args["rsnew"]["Prio"]. "</p>"; // Append additional content
    $email->Content .= "<p>Status: " .$FStatus. "</p>"; // Append additional content
    $email->Content .= "<p>NextStatus: " .$FNextStatus. "</p>"; // Append additional content
        } 
}

   //Send E-Mail to Vorsitz 
    if (CurrentPageID() == "edit"){   
        if ($this->Status->CurrentValue == 8) { // If Add page
            $email->Recipient =  $Vorstiz;
            $email->Subject = "3In Sachen " .$args["rsnew"]["GNr"]; // Change subject
            $email->Content = "<p>Fall mit GNr: ".$args["rsnew"]["GNr"]. " zwischen den Parteien " .$args["rsnew"]["Parteien"]. " wurde aktualisiert</p>"; // Append additional content
            $email->Content .= "<p>VS: ".$args["rsnew"]["Vs"]. " Gs: " .$args["rsnew"]["Gs"]."</p>"; // Append additional content
            $email->Content .= "<p>Ausfertigung: ".$Ausfertigung."</p>";
            $email->Content .= "<p>Priorität: ".$args["rsnew"]["Prio"]. "</p>"; // Append additional content
           $email->Content .= "<p>Status: " .$FStatus. "</p>"; // Append additional content
           $email->Content .= "<p>NextStatus: " .$FNextStatus. "</p>"; // Append additional content
              }
} 
  
   //Send EMail to Ausfertigung
   if (CurrentPageID() == "edit"){ 
      if(($args["rsnew"]["Status"] == 9) OR (($args["rsnew"]["Prio"] == "Eilig") AND ($args["rsnew"]["Anonym"]  == 1 ))) { // If Add page
               $email->Recipient =  $this->Bearbeiter->CurrentValue;
               $email->Subject = "4In Sachen " .$args["rsnew"]["GNr"]; // Change subject
               $email->Content = "<p>Fall mit GNr: ".$args["rsnew"]["GNr"]. " zwischen den Parteien " .$args["rsnew"]["Parteien"]. " wurde aktualisiert</p>"; // Append additional content
              $email->Content .= "<p>VS: ".$args["rsnew"]["Vs"]. " Gs: " .$args["rsnew"]["Gs"]."</p>"; // Append additional content
              $email->Content .= "<p>Ausfertigung: ".$Ausfertigung."</p>";
              $email->Content .= "<p>Priorität: ".$args["rsnew"]["Prio"]. "</p>"; // Append additional content
              $email->Content .= "<p>Status: " .$FStatus. "</p>"; // Append additional content
              $email->Content .= "<p>MyPrios: " .$args["rsnew"]["Prio"]. "Old ".$args["rsold"]["Prio"] ."</p>"; // Append additional content
              $email->Content .= "<p>NextStatus: " .$FNextStatus. "</p>"; // Append additional content
                           } 
      }


   //Send E-Mail to Kanzlei
   if (CurrentPageID() == "edit"){ 	      
 if ($args["rsnew"]["Status"]  == 13) { // If Add page
                   	$email->Recipient =  $Kanzlei;
                       	$email->Subject = "5In Sachen " .$args["rsnew"]["GNr"]; // Change subject
                       	$email->Content = "<p>Fall mit GNr: ".$args["rsnew"]["GNr"]. " zwischen den Parteien " .$args["rsnew"]["Parteien"]. " wurde aktualisiert</p>"; // Append additional content
                        $email->Content .= "<p>VS: ".$args["rsnew"]["Vs"]. " Gs: " .$args["rsnew"]["Gs"]."</p>"; // Append additional content
                        $email->Content .= "<p>Ausfertigung: ".$args["rsnew"]["Bearbeiter"]."</p>";
                        $email->Content .= "<p>Priorität: ".$args["rsnew"]["Prio"]. "</p>"; // Append additional content
                        $email->Content .= "<p>Status: " .$FStatus. "</p>"; // Append additional content
                        $email->Content .= "<p>NextStatus: " .$FNextStatus. "</p>"; // Append additional content
                       	                    }
		    }
       return true;
   }

mpol_ch


mobhar
User
Posts: 11660

Post by mobhar »

Your code looks confusing to me. You should put all conditions that belongs to the Edit Page in one block instead creating it in some blocks. Just my two cents.


Post Reply