By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

[PHPMailer] Why still NULL after failure?

P: n/a
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.com";
$mail->From = "se****@acme.com";
$mail->FromName = "From Server";
$mail->AddAddress("su*****@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.
Sep 9 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Gilles Ganault" <no****@nospam.comha scritto nel messaggio
news:ro********************************@4ax.com...
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.com";
$mail->From = "se****@acme.com";
$mail->FromName = "From Server";
$mail->AddAddress("su*****@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
Sep 9 '08 #2

P: n/a
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.com";
$mail->From = "se****@acme.com";
$mail->FromName = "From Server";
$mail->AddAddress("su*****@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.
js*******@attglobal.net
==================

Sep 9 '08 #3

P: n/a
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.sourceforge.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.
Sep 10 '08 #4

P: n/a
"Gilles Ganault" <no****@nospam.comschreef in bericht
news:ro********************************@4ax.com...
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.

Sep 10 '08 #5

P: n/a
On Thu, 11 Sep 2008 05:22:08 GMT, Tim Roberts <ti**@probo.comwrote:
>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:
uninitialized (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.
Sep 12 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.