Announcement

Collapse
No announcement yet.

Save email sent APP control and error message

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Save email sent APP control and error message

    Hi, I have a control application that sends email providers entered into a database, the applicaizone sends the same email to one or more selected addresses and passed by a grid.

    The control application works perfectly, send emails correctly, but I would like to make it more complete with two important functions.

    1) I WANT THAT COMMUNICATIONS SENT TO SUPPLIERS HAVE REGISTERED IN databese comunicazioni_fornitori

    2) I would like to enter a confirmation message sending email or error on error and relative addressing a grid_fornitori

    The problem for point 1) is that an email can be sent to multiple contacts and in that case you can record in the DB of comunicazioni_fornitori records separated?

    Here is the code that has the control application

    $ var_email_to = [var_email_to];
    $ var_email_invio email_invio = {};
    $ var_oggetto = {object};
    $ var_messaggio = {text};

    / **
    * Send a simple email
    * /

    // Email parameters
    $ mail_smtp_server = 'smtp.AAAAAA.com'; // SMTP server name or IP address
    $ mail_smtp_user = 'info@AAAAAA.com'; // SMTP user name
    $ mail_smtp_pass = 'bbbbbbbbb'; // SMTP password
    $ = $ mail_from var_email_invio; // From email
    $ = $ mail_to var_email_to; // To email
    $ = $ mail_subject var_oggetto; // Message subject
    $ = $ mail_message var_messaggio; // Message body
    $ mail_format = 'H'; // Message format: (T) ext or (H) tml

    // Send email ";
    sc_mail_send ($ mail_smtp_server,
    $ mail_smtp_user,
    $ mail_smtp_pass,
    $ mail_from,
    $ mail_to,
    $ mail_subject,
    $ mail_message,
    $ mail_format);

  • #2
    Go to your grid and change your run button.
    Run OnRecord:
    [arr_email_to][] = {supplier_id};

    Now change your onFinish code

    Run OnFinish
    if (count ([arr_email_to])> 0)
    {
    $var_email_to = "(".implode (',', [arr_email_to]).")";
    sc_redir(control_email_fornitori,var_email_to = $var_email_to);
    }

    In the control app:

    $email_sql = "SELECT GROUP_CONCAT(email SEPARATOR ';') FROM supplier WHERE supplier_id IN [var_email_to]";
    sc_lookup(rs,$email_sql);
    if(isset({rs[0][0]}))
    {
    $var_mail_to = {rs[0][0]};
    }

    After your email has been sent (or not). http://www.scriptcase.net/docs/en_us...s#sc_mail_send

    if ({sc_mail_ok})
    {
    $result = "Email sent with sucess!!";
    }
    else
    {
    $result = {sc_mail_erro};
    }

    Than update your table(s) with: UPDATE ... WHERE supplier_id IN [var_email_to]


    jsb

    Comment


    • #3
      Hello, thank you again for the information.
      But one question, in the database of communications sent I want to save separately the following fields;
      email provider = email_fornitore
      subject of the communication object =
      communication sent text = communication

      Please show me how to change the code?

      Comment


      • #4
        Who can help me please ???

        Comment


        • #5
          Excuse me, where in the application code control I need to enter this code:

          $ email_sql = "SELECT GROUP_CONCAT (email SEPARATOR ';') FROM WHERE supplier supplier_id IN [var_email_to]";
          sc_lookup (rs, $ email_sql);
          if (isset (rs {[0] [0]}))
          {
          var_mail_to $ rs = {[0] [0]};
          }

          Comment


          • #6
            Right in front of your email stuff.
            Delete the line '$var_email_to = [var_email_to]' and replace it with the code provided.

            $email_sql = "SELECT GROUP_CONCAT(email SEPARATOR ';') FROM supplier WHERE supplier_id IN [var_email_to]";
            sc_lookup(rs,$email_sql);
            if(isset($rs) && !emtpy($rs))
            {
            $var_mail_to = {rs[0][0]};
            }
            else
            {
            sc_error_message('something went wrong!');
            sc_error_exit();
            }
            $ var_email_invio email_invio = {};
            $ var_oggetto = {object};
            $ var_messaggio = {text};

            / **
            * Send a simple email
            * /
            ...



            After your email has been sent you can do something like the following to keep track of emails sent.

            if ({sc_mail_ok})
            {
            $result = "Email sent with sucess!!";
            }
            else
            {
            $result = {sc_mail_erro};
            }

            $ins_sql = "INSERT INTO comunicazioni_fornitori (supplier, email, subject, result) SELECT supplier_id, supplier_email, $mail_subject, $result FROM supplier WHERE supplier_id IN [var_mail_to";
            sc_exec_sql($ins_sql);

            You might of course adapt the code to your needs but this should point you in the right direction.

            jsb

            Comment


            • #7
              Hello, please help me .... it is very important.
              I entered the settings you specified, but the application does not work, does not print in the application control the emails that I have selected in the grid.

              That's all my code:

              $email_sql = "SELECT GROUP_CONCAT(email SEPARATOR ';') FROM supplier WHERE supplier_id IN [var_email_to]";
              sc_lookup(rs,$email_sql);
              if(isset($rs) && !emtpy($rs))
              {
              $var_mail_to = {rs[0][0]};
              }
              else
              {
              sc_error_message('Messaggio non inviato!');
              sc_error_exit();
              }
              $var_email_invio = {email_invio};
              $var_oggetto = {oggetto};
              $var_messaggio = {text};

              /**
              * Send a simple email
              */

              // Email parameters
              $mail_smtp_server = 'smtp.aaaaaa.com'; // SMTP server name or IP address
              $mail_smtp_user = 'info@aaaaa.com'; // SMTP user name
              $mail_smtp_pass = 'vvvvvvvvvv'; // SMTP password
              $mail_from = $var_email_invio; // From email
              $mail_to = $var_email_to; // To email
              $mail_subject = $var_oggetto; // Message subject
              $mail_message = $var_messaggio; // Message body
              $mail_format = 'H'; // Message format: (T)ext or (H)tml

              // Send email";
              sc_mail_send($mail_smtp_server,
              $mail_smtp_user,
              $mail_smtp_pass,
              $mail_from,
              $mail_to,
              $mail_subject,
              $mail_message,
              $mail_format);

              if ({sc_mail_ok})
              {
              $result = "Email Inviata con Successo!!";
              }
              else
              {
              $result = {sc_mail_erro};
              }

              $ins_sql = "INSERT INTO fornitoricomunicazioni (supplier, email, oggetto_comunicazione, comunicazione) SELECT supplier_id, supplier_email, $var_oggetto, $var_messaggio FROM supplier WHERE supplier_id IN [var_mail_to";
              sc_exec_sql($ins_sql);

              Comment


              • #8
                $email_sql = "SELECT GROUP_CONCAT(email SEPARATOR ';') FROM supplier WHERE supplier_id IN [var_email_to]";
                sc_lookup(rs,$email_sql);
                if(isset($rs) && !emtpy($rs)) <-----
                ...
                May be you should try !empty instead of !emtpy. :-)

                And don't try everything at the same time. Step by step.
                Start with the grid, does the Run button work? Did you apply the suggestions posted earlier?
                Then see if the email_sql statement delivers what you expect.
                Also, try it without the insert statement at the end, you can add it when everything else works.
                Are there any error messages? 'Won't work' doesn't help very much.

                jsb

                Comment


                • #9
                  Hello, the mistake that I printed before loading the control application is:
                  Undefined Variable: supplier_id

                  And in the grid in the RUN button I;
                  OnRecord
                  [arr_email_to] [] = {} supplier_id;

                  OnFinish
                  if (count ([arr_email_to])> 0)
                  {
                  $ var_email_to = "(" .implode (',', [arr_email_to]). ")";
                  sc_redir (control_email_fornitori, var_email_to = $ var_email_to);
                  }

                  it is as if he can not understand that must pass the email.

                  Comment


                  • #10
                    Ok, let's do some testing.
                    Change this:
                    OnFinish
                    if (count ([arr_email_to])> 0)
                    {
                    $ var_email_to = "(" .implode (',', [arr_email_to]). ")";
                    sc_redir (control_email_fornitori, var_email_to = $ var_email_to);
                    }
                    to this:

                    Code:
                    OnFinish
                    if (count ([arr_email_to])> 0)
                    {
                        $ var_email_to = "(" .implode (',', [arr_email_to]). ")";
                        //sc_redir (control_email_fornitori, var_email_to = $ var_email_to);
                        print_r($var_email_to);
                        sc_exit();
                    }
                    Do you get what you want?

                    jsb

                    Comment


                    • #11
                      Hello, I tried the code but the error remains the same.
                      the code I added to

                      OnFinish is:
                      if (count ([arr_email_to])> 0)
                      {
                      $ var_email_to = "(" .implode (',', [arr_email_to]). ")";
                      sc_redir (control_email_fornitori, var_email_to = $ var_email_to);
                      print_r ($ var_email_to);
                      sc_exit ();
                      }

                      Comment


                      • #12
                        Run OnRecord:
                        [arr_email_to][] = {supplier_id};

                        Do you have the field name {supplier_id} (it should be the primay key) in your grid/table or is it named differently?

                        jsb

                        Comment


                        • #13
                          In my onRecord the grid have exactly

                          Run OnRecord:
                          [arr_email_to] [] = {} supplier_id;

                          ... Unfortunately it does not work

                          Comment


                          • #14
                            in the grid in OnScriptlnit I code:
                            [arr_email_to] = array ();

                            Perhaps here is the error.

                            Comment


                            • #15
                              Originally posted by peraziende View Post
                              in the grid in OnScriptlnit I code:
                              [arr_email_to] = array ();

                              Perhaps here is the error.
                              Nope, that's correct.
                              The error is related to the field {supplier_id}. That's what SC is complaining about.

                              jsb

                              Comment

                              Working...
                              X