473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

[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.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
5 2716

"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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daniel Loose | last post by:
Hi, a friend was so kind to host my php scripts. but when they use phpmailer (or other PHP mail facilities) to email e.g. to an invalid address, the returning error message appears in *my...
1
by: Leszek | last post by:
Hi. I have problem with phpMailer 1.73 (windows version) After copying both class.phpmailer and class.smtp and also language file phpmailer.lang-pl to my php include directory im getting this...
3
by: Leszek | last post by:
Hi. I have problem with phpMailer 1.73 (windows version) After copying both class.phpmailer and class.smtp and also language file phpmailer.lang-pl to my php include directory im getting this...
0
by: SirShurf | last post by:
Hi, I am using a phpmailer class to send some forms over the email... And the problem is, that some ppl (especially problematic for me is the buyer....) getting the email as rough data (sorce...)...
2
by: prasenjit2007 | last post by:
Hello, can u help me sending Email with attachments using the Class phpMailer. On the website I have a link to an html form in which I input the parameters with the names 1)from(textbox name)...
1
by: abasel | last post by:
I've been looking everywhere for a forum dedicated to this script but so far could only find a mailing list. I Have two questions: 1) What doe the following mean? Warning: fsockopen() :...
9
by: Lucanos | last post by:
Hi All, I am currently using PHPMailer to send out a set of emails on the execution of a PHP Script (obviously). My problem is that the PHPMailer action is returning a "true" result each time...
4
by: mukeshrasm | last post by:
Hi! I want to use phpmailer class to send mail using smtp.I have downloaded the phpmailer and then i followed it's README file where it is mentioned that "Copy class.phpmailer.php into your php.ini...
0
by: mukeshrasm | last post by:
Hi! I want to use phpmailer class to send mail using smtp.I have downloaded the phpmailer and then i followed it's README file where it is mentioned that "Copy class.phpmailer.php into your php.ini...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.