3 Replies Latest reply on Aug 1, 2008 9:30 AM by Günter Schenk

    Customising the Email Trigger

      I've got two email triggers and they work fine. <br />Now I want to customise one of the triggers so that if a variable, regtype, is set to say "1" the trigger's $emailObj-&gt;setContent will be one message and if the variable is set to regtype "2" the trigger's $emailObj-&gt;setContent will be a different message (see below). <br />Here's what I thought would work... <br /> <br />-------------------------------------------------------------------------- <br /> <br />//I've defined my variable, regtype: <br />$regtype=-1; <br />if (isset($_POST['regtype'])) $regtype = (int)$_POST['regtype']; <br /> <br />//and then altered the trigger as follows: <br /> <br />//start Trigger_SendEmail1 trigger <br />//remove this line if you want to edit the code by hand <br />function Trigger_SendEmail1(&amp;$tNG) { <br /> $emailObj = new tNG_Email($tNG); <br /> $emailObj-&gt;setFrom("webmaster@yoursite.co.uk"); <br /> $emailObj-&gt;setTo("{email}"); <br /> $emailObj-&gt;setCC(""); <br /> $emailObj-&gt;setBCC(""); <br /> $emailObj-&gt;setSubject("New Technology Registration with yoursite"); <br /> //WriteContent method <br /> // Show IF Regtype is business <br />if ($regtype == '3') { <br />?&gt; <br /><?php<br />  $emailObj->setContent("Dear {firstname},\n\nThank you for registering!\nYou may now log in using your email address as your username along with the password you supplied - {password}. \n\nBest regards,\n\nThe yoursite Team");<br />?> <br /><?php } <br />  // Show IF Regtype is NOT business <br />?> <br /><?php <br />if ($regtype != '3') {<br />?> <br /><?php<br />  $emailObj->setContent("Dear {firstname},\n\nThank you for registering!\nYour registration is awaiting approval after which we will send you your username and password to log in. \nIf you do not hear from us within 1 working day please contact us by emailing support@yoursite.co.uk\n\nBest regards,\n\nThe yoursite Admin Team");<br />?> <br /><?php } <br />?> <br />
        • 1. Re: Customising the Email Trigger
          Günter Schenk Level 4
          Hi Chris,

          looks like you declared the variable $regtype outside the function Trigger_SendEmail1 ? The scope of a PHP variable is the context within which it is defined -- in this case it´s the function which apparently doesn´t yet "see" the variable respectively its value. By adding...

          global $regtype;

          ...to the function it would be possible to retrieve such an "outside" variable.

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: Customising the Email Trigger
            Level 1
            Dear Günter,

            Respect to the guru of the Adobe Forums!
            Thanks for the swift response. I've tried to declare the variable as a global both before and even inside the function...

            function Trigger_SendEmail1(&$tNG) {
            global $regtype;
            $emailObj = new tNG_Email($tNG); //etc

            but to no avail :(

            I've tried using single and double quotes when I interrogate the variable. Could it just be that the email function in ADDT just won't allow any conditional content?
            BTW I've often wondered what it means by:
            //remove this line if you want to edit the code by hand
            Which line does one remove and why?

            Chris
            • 3. Re: Customising the Email Trigger
              Günter Schenk Level 4
              Hi Chris,

              ------
              Could it just be that the email function in ADDT just won't allow any conditional content?
              ------

              I´ve never tried that so far, so I guess we´ll just have to experiment a little ;-)

              To my knowledge $_POST['whatever'] variables are also not detected in this context, so it would be cool to know if using ADDT´s transaction values will do the trick:

              if (isset($tNG->getColumnValue("regtype"))) $regtype = (int)$tNG->getColumnValue("regtype");

              Does that work ?

              BTW, plan B would be to simply create a third send email instance (say, SendEmail3) and have this one send the "IF Regtype is NOT business" contents -- that´s actually a very simple step, because you can define the "$regtype != '3'" condition in the Condition Builder, means that "$regtype" would be the corresponding transaction value.

              Stuff like this usually works for me, and if this works for you too, you should of course modify the current SendEmail1 instance to send the "IF Regtype is business" contents -- also by applying the Condition Builder on this instance, but now with the condition: transaction value == '3'

              -----
              BTW I've often wondered what it means by:
              //remove this line if you want to edit the code by hand
              Which line does one remove and why?
              -----

              By removing this very comment line you´ll "tell" Dreamweaver´s server behaviours panel that it´s still to be regarded as editable Server Behaviour, but is not supposed to be edited using the standard Send Email GUI -- what wouldn´t work anyways due to your modications. If you´d leave that comment line there, the corresponding Server Behaviour might either vanish from the list or be displayed as "broken" (a red exclamation mark)

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver