[PHPMailer] Why still NULL after failure?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gilles Ganault

    [PHPMailer] Why still NULL after failure?

    Hello

    To handle an occasionnal flaky ADSL connection, I updated the
    database that handles incoming calls to have a column that is set to
    NULL, and then updated to either Y or N depending on whether a PHP CLI
    script was able to send a notification e-mail to support.

    To send an e-mail through out ISP's SMTP server, I'm using PHPMailer
    2.0.0 rc3 http://phpmailer.sourceforge.net which worked fine until we
    had some connection loss. I'm at a loss as to why some (not all) new
    call records are left to NULL instead of being updated to Y or N :-/

    Here's the code:

    =========
    require("/usr/local/share/asterisk/agi-bin/php_mailer/class.phpmailer .php");
    $mail = new PHPMailer();

    $mail->IsSMTP();
    $mail->Host = "smtp.isp.c om";
    $mail->From = "server@acme.co m";
    $mail->FromName = "From Server";
    $mail->AddAddress("su pport@acme.com" );
    $mail->Subject = "Dummy subject";
    $body = "Dummy body";
    $mail->Body = $body;
    $mail->WordWrap = 50;

    //Why do some records remain to NULL?
    $sql = "UPDATE calls SET calls_sent='%s' WHERE calls_id=$calls _id";
    if(!$mail->Send()) {
    //If failed, update record with calls_sent="n"
    $sql = sprintf($sql,"n ");
    $dbh->exec($sql);
    $dbh = null;
    exit("Mailer error: " . $mail->ErrorInfo . "\n");
    } else {
    $sql = sprintf($sql,"y ");
    $dbh->exec($sql);
    $dbh = null;
    exit(0);
    }=========

    Any idea why it doesn't do what it's supposed to?

    Thank you.
  • J2Be.com

    #2
    Re: [PHPMailer] Why still NULL after failure?


    "Gilles Ganault" <nospam@nospam. comha scritto nel messaggio
    news:ro4dc49r3b 9dh2akts0kkvhbt gl34q0od9@4ax.c om...
    Hello
    >
    To handle an occasionnal flaky ADSL connection, I updated the
    database that handles incoming calls to have a column that is set to
    NULL, and then updated to either Y or N depending on whether a PHP CLI
    script was able to send a notification e-mail to support.
    >
    To send an e-mail through out ISP's SMTP server, I'm using PHPMailer
    2.0.0 rc3 http://phpmailer.sourceforge.net which worked fine until we
    had some connection loss. I'm at a loss as to why some (not all) new
    call records are left to NULL instead of being updated to Y or N :-/

    I personally suggest to always not use NULLs in the database... except some
    particular cases. If there are problems into inserting something in the
    database you will notice it immediately and if you set a default for the
    records you will always avoid possible problems... in any case the NULLs, in
    most cases, are the culprip ot several useless records.
    It's my personal impression.

    Here's the code:
    >
    =========
    require("/usr/local/share/asterisk/agi-bin/php_mailer/class.phpmailer .php");
    $mail = new PHPMailer();
    >
    $mail->IsSMTP();
    $mail->Host = "smtp.isp.c om";
    $mail->From = "server@acme.co m";
    $mail->FromName = "From Server";
    $mail->AddAddress("su pport@acme.com" );
    $mail->Subject = "Dummy subject";
    $body = "Dummy body";
    $mail->Body = $body;
    $mail->WordWrap = 50;
    >
    //Why do some records remain to NULL?
    $sql = "UPDATE calls SET calls_sent='%s' WHERE calls_id=$calls _id";
    if(!$mail->Send()) {
    use
    if($mail->Send() === false)
    because the function Send() returns true or false from what I know
    //If failed, update record with calls_sent="n"
    $sql = sprintf($sql,"n ");
    $dbh->exec($sql);
    $dbh = null;
    exit("Mailer error: " . $mail->ErrorInfo . "\n");
    } else {
    $sql = sprintf($sql,"y ");
    $dbh->exec($sql);
    $dbh = null;
    exit(0);
    }=========


    if($mail->Send() === false)
    $retmail = 'n';
    } else {
    $retmail = 'y';
    }

    $sql = "UPDATE calls SET calls_sent='" . $retmail . "' WHERE calls_id=" .
    $calls_id;
    $dbh->exec($sql);
    $dbh = null;
    exit(0);

    This should be more clear....

    Try to detect the NULLs by logging the update strings and the eventual sql
    errors.
    If you don't want headaches just set the records to not NULLs and with the
    default to no. I personally use tiny ints to save the yes/no records.


    Regards

    L. A. Iarrusso


    Comment

    • Jerry Stuckle

      #3
      Re: [PHPMailer] Why still NULL after failure?

      Gilles Ganault wrote:
      Hello
      >
      To handle an occasionnal flaky ADSL connection, I updated the
      database that handles incoming calls to have a column that is set to
      NULL, and then updated to either Y or N depending on whether a PHP CLI
      script was able to send a notification e-mail to support.
      >
      To send an e-mail through out ISP's SMTP server, I'm using PHPMailer
      2.0.0 rc3 http://phpmailer.sourceforge.net which worked fine until we
      had some connection loss. I'm at a loss as to why some (not all) new
      call records are left to NULL instead of being updated to Y or N :-/
      >
      Here's the code:
      >
      =========
      require("/usr/local/share/asterisk/agi-bin/php_mailer/class.phpmailer .php");
      $mail = new PHPMailer();
      >
      $mail->IsSMTP();
      $mail->Host = "smtp.isp.c om";
      $mail->From = "server@acme.co m";
      $mail->FromName = "From Server";
      $mail->AddAddress("su pport@acme.com" );
      $mail->Subject = "Dummy subject";
      $body = "Dummy body";
      $mail->Body = $body;
      $mail->WordWrap = 50;
      >
      //Why do some records remain to NULL?
      $sql = "UPDATE calls SET calls_sent='%s' WHERE calls_id=$calls _id";
      if(!$mail->Send()) {
      //If failed, update record with calls_sent="n"
      $sql = sprintf($sql,"n ");
      $dbh->exec($sql);
      $dbh = null;
      exit("Mailer error: " . $mail->ErrorInfo . "\n");
      } else {
      $sql = sprintf($sql,"y ");
      $dbh->exec($sql);
      $dbh = null;
      exit(0);
      }=========
      >
      Any idea why it doesn't do what it's supposed to?
      >
      Thank you.
      >
      Gilles,

      This looks like it should work just fine. The only thing I can think of
      is if you're looking at the wrong problem and $calls_id is not set properly.

      Of course, it will only set one row to 'y' or 'n' before exiting, so it
      won't work with multiple emails. But it looks like that's what you want.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • C. (http://symcbean.blogspot.com/)

        #4
        Re: Why still NULL after failure?

        On 9 Sep, 16:25, Gilles Ganault <nos...@nospam. comwrote:
        Hello
        >
        To handle an occasionnal flaky ADSL connection, I updated the
        database that handles incoming calls to have a column that is set to
        NULL, and then updated to either Y or N depending on whether a PHP CLI
        script was able to send a notification e-mail to support.
        >
        To send an e-mail through out ISP's SMTP server, I'm using PHPMailer
        2.0.0 rc3http://phpmailer.sourc eforge.netwhich worked fine until we
        had some connection loss. I'm at a loss as to why some (not all) new
        call records are left to NULL instead of being updated to Y or N :-/
        >
        Your premise is basically flawed, although SMTP is not completely
        transaction safe any compliant MTA must be capable of queueing and
        retrying the sending of mail: really you should get your local MTA to
        handle the outgoing mail (using your service provider as a smart
        relay). Even if it gets as far as your service provider, there is no
        guarantee of delivery - but using the built-in DSN functionality makes
        more sense as a way of determining status rather than whether it got
        to your provider.

        Of course, if you can deploy code at the remote end, then there's
        nothing to stop you layering a transactionally secure messaging system
        on top of SMTP.

        C.

        Comment

        • mijn naam

          #5
          Re: [PHPMailer] Why still NULL after failure?

          "Gilles Ganault" <nospam@nospam. comschreef in bericht
          news:ro4dc49r3b 9dh2akts0kkvhbt gl34q0od9@4ax.c om...
          Hello
          >
          To handle an occasionnal flaky ADSL connection, I updated the
          database that handles incoming calls to have a column that is set to
          NULL, and then updated to either Y or N depending on whether a PHP CLI
          script was able to send a notification e-mail to support.
          >
          To send an e-mail through out ISP's SMTP server, I'm using PHPMailer
          2.0.0 rc3 http://phpmailer.sourceforge.net which worked fine until we
          had some connection loss. I'm at a loss as to why some (not all) new
          call records are left to NULL instead of being updated to Y or N :-/
          >
          Here's the code:
          [...]
          //Why do some records remain to NULL?
          $sql = "UPDATE calls SET calls_sent='%s' WHERE calls_id=$calls _id";
          if(!$mail->Send()) {
          //If failed, update record with calls_sent="n"
          $sql = sprintf($sql,"n ");
          $dbh->exec($sql);
          $dbh = null;
          exit("Mailer error: " . $mail->ErrorInfo . "\n");
          } else {
          $sql = sprintf($sql,"y ");
          $dbh->exec($sql);
          $dbh = null;
          exit(0);
          }=========
          >
          Any idea why it doesn't do what it's supposed to?

          The PHP part is simple: either true or false, no exceptions.

          This means the problem is in the SQL part and you will need to debug that.
          It also means this is the wrong newsgroup for this particular
          problem/question.

          Comment

          • Gilles Ganault

            #6
            Re: [PHPMailer] Why still NULL after failure?

            On Thu, 11 Sep 2008 05:22:08 GMT, Tim Roberts <timr@probo.com wrote:
            >I don't know what are you trying to say here, but this advice doesn't seem
            >to be founded on anything concrete. In fact, what he describes seems to be
            >the perfect use for NULL. It provides him a 3-state solution:
            >uninitialize d (NULL), yes, and no.
            I was about to ask too because I didn't know there were a difference
            between NULL and a column that hasn't been set when creating the
            record.
            >But that just masks the problem. He wants to know the difference between
            >"never set" and "set to y" and "set to n".
            I'm not positive that's what the cause was, because some calls do work
            OK (the column is set to either Y or N), while some calls leave that
            column empty. I'll see if I can find out what is causing this error.
            I'll also upgrade to the latest PHPMail code.

            Thanks guys for the help.

            Comment

            Working...