Announcement

Collapse
No announcement yet.

How can I trap the error when the sc_mail_send command fails?

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

  • How can I trap the error when the sc_mail_send command fails?

    Hi guys,
    I happened to have experienced a problem related to my host's smtp mail system... not SC6 this time

    The error starts off with:
    Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.webfaction.com [php_network_getaddresses: getaddrinfo failed: Name or service not known #0]' in
    <I deleted the rest as it has path and stuff I would rather not expose>

    But it did bring to life a problem - when this failure happened , it was at the last step of my user registration. That all actually worked well, except for the email not going out. PHP dumped a big dozen lines of errors on the smtp. What can I do to capture errors with the sc_mail_send command? If the email fails, I would rather just not have it sent, but take the user to a redirect page for greetings and info that way.

    BTW - I read the help on that comand and have tried to use the code in the example - HOWEVER, this only seems to work on logical errors. By that I mean that if you get the type of fatal error I have experienced, it dies before the error code below can help you log anything. What should I do?

    Example code:

    Ex. 3: No user and password.
    sc_mail_send([glo_smtp], '', '', 'from.netmake.com.br', {to}, {sunject}, {message}, 'H', '', '', '', '', [glo_att]);

    The amount of emails sent will be stored at the special variable "sc_mail_count".

    If any error happend when the scriptcase try to send the email, the variable "sc_mail_ok" will recieve "false" and the error message will be stored on the variavle "sc_mail_erro".

    Ex.4 :
    sc_mail_send([glo_smtp], '', '', 'from@netmake.com.br', {to}, {subject}, {message}, 'H');

    if ({sc_mail_ok})
    {
    echo "sent {sc_mail_count} e-mail(s) with sucess!!";
    }
    else
    {
    sc_erro_mensagem({sc_mail_erro});
    }

    Thanks,
    Jamie
    Last edited by onmountain; 07-24-2013, 09:55 PM.

  • #2
    Hi Jamie,
    Not sure if it will work, but did you try to trap the error by try...catch?
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      Hello Jamie and Albert.
      I'm facing the same problem. The mail is not sent and I don't have a valid error to show to user.
      How did you solve this issue ??

      I also searched on Application Language for 'sc_mail_erro' but I didn't find anything. Is it an embedded message ?

      I did also
      else // No row found
      {
      sc_error_message({sc_mail_erro} );
      sc_error_message('Attenzione, E-Mail del Cliente, Agente o Manager mancanti o non corrette. Verificare !');
      echo "<script type='text/javascript'>alert('Attenzione, E-Mail del Cliente, Agente o Manager mancanti o non corrette. Verificare !');</script>";
      sc_redir(form_orders, "_parent");
      }

      Comment

      Working...
      X