473,761 Members | 9,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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 = "se****@acme.co m";
$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 2741

"Gilles Ganault" <no****@nospam. comha scritto nel messaggio
news:ro******** *************** *********@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 = "se****@acme.co m";
$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.c om";
$mail->From = "se****@acme.co m";
$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*******@attgl obal.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.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.
Sep 10 '08 #4
"Gilles Ganault" <no****@nospam. comschreef in bericht
news:ro******** *************** *********@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.

Sep 10 '08 #5
On Thu, 11 Sep 2008 05:22:08 GMT, Tim Roberts <ti**@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.
Sep 12 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2446
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 friend's email inbox* (recipient - or sender? - is "wwwrun" of my friend's machine). I guess you understand which problem I mean. To fix the problem, I would like to understand what is going on here - in the mail header, i did set replyto, x-sender...
1
12582
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 error when I'm trying to use phpMailer: Mailer Error: Language string failed to load: recipients_failed Does anyone konw the reason for this error?
3
2590
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 error when I'm trying to use phpMailer: Mailer Error: Language string failed to load: recipients_failed Does anyone know the reason for this error?
0
1426
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...) here is the emal itself as they get it (the headers are below...) Code: X-Tour4Less.co.il Mailer: MIME-Version: 1.0
2
4557
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) 2)To 3) Subject 4) Message5) File input(name abc) - to be sent as an attachment. This form calls the Class PhpMailer through another form with the following code to send the mail. <?php ini_set("include_path",...
1
2096
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() : php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/intern/public_html/demo/lib/phpmailer/class.smtp.php on line 105
9
2433
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 it is executed, but not every email generated by this action is actually being sent. My account is hosted on HostMonster, and is pointed at the localhost as the SMTP server.
4
4939
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 include_path. If you are using the SMTP mailer then place class.smtp.php in your path as well", but I don't know where to paste the class.phpmailer.php into my php.ini include_path. I am using WAMP Server. and it is in c drive.
0
4350
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 include_path. If you are using the SMTP mailer then place class.smtp.php in your path as well", but I don't know where to paste the class.phpmailer.php into my php.ini include_path. In my php.ini file the include path is commented and it is like ...
0
9531
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.