473,383 Members | 1,880 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,383 software developers and data experts.

mail () breaks loop

I seem to be having troubles with this page....
It's an automated mailing script...
Steps:
- system checks on x dates the variables linked to a maintenance
contract (query on db)
- when variable matches given element is queries the db again to
retrieve the contact data linked to the maintenance system
- I then sends an email to the different contacts linked to that
maintenance contract
- then the script schoul continue looping to the next maintenance
contract
BUT: somehow, the script stop after sending the first email.
Why?
<?
// global variables
require("DbConnect.class.php");
// -------------- calculate dates ------
$yearNow = date(Y);
$monthNow = date(m);
//$monthNow = 12;
$dayNow = date(d);
$now = date(Ymd);
$mydateBeginMonth = date("Ym01");
$mydateHalfMonth = date("Ym15");
$monthPlusOne = $monthNow + 1;
$monthPlusTwo = $monthNow + 2;
$yearPlusOne = $yearNow;
$yearPlusTwo = $yearNow;
// ------------------------- Plus 1
month ------------------------------------
//
---------------------------------------------------------------------------
// December = NOW
if ($monthPlusOne == 13){
$monthPlusOne = "01";
$yearPlusOne = $yearNow + 1;
}
$myDatePlusOneBeginMonth = $yearPlusOne."".$monthPlusOne."01";
$myDatePlusOneHalfMonth = $yearPlusOne."".$monthPlusOne."15";
// ------------------------- Plus 2
months ------------------------------------
//
---------------------------------------------------------------------------
// November = NOW
if ($monthPlusTwo == 13){
$monthPlusTwo = "01";
$yearPlusTwo = $yearNow + 1;
}
// December = NOW
if ($monthPlusTwo == 14){
$monthPlusTwo = "02";
$yearPlusTwo = $yearNow + 1;
}
$myDatePlusTwoBeginMonth = $yearPlusTwo."".$monthPlusTwo."01";
$myDatePlusTwoHalfMonth = $yearPlusTwo."".$monthPlusTwo."15";
echo $mydateBeginMonth." - ".$mydateHalfMonth."<br><br><hr><br>";
echo $myDatePlusOneBeginMonth." -
".$myDatePlusOneHalfMonth."<br><br><hr><br>";
echo $myDatePlusTwoBeginMonth." -
".$myDatePlusTwoHalfMonth."<br><br><hr><br>";
//************************************************** *****************
$db->open() or die($db->error());
$db->query("SELECT maintenanceRefNumber, endDate, contactIDdistributor,
contactIDreseller, serialID, endUserID FROM TBL_maintenance ORDER BY
endDate
ASC") or die($db->error());
$i = 1;
while ($row=$db->fetcharray()) {
$maintenanceRefNumber = $row[0];
$endDate = $row[1];
$contactIDdistributor = $row[2];
$contactIDreseller = $row[3];
$serialID = $row[4];
$endUserID = $row[5];
//echo "$i - $maintenanceRefNumber - $endDate<br>";
list($day, $month, $year) = explode(".", $endDate);
$myMaintenanceDate = $year."".$month."".$day;
if (($myMaintenanceDate >= $mydateBeginMonth) && ($myMaintenanceDate <
$mydateHalfMonth)) {
// ----------------- GET DATA
----------------------------------------
//
-------------------------------------------------------------------
$db->query("SELECT tbl_product.productNaam,
tbl_product.productVersie,
tbl_product.productType FROM tbl_product, tbl_serials WHERE
(tbl_serials.serialID = $serialID) AND (tbl_serials.productID =
tbl_product.productID)") or die($db->error());
while ($row2=$db->fetcharray()) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}
$db->query("SELECT email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDdistributor") or die($db->error());
while ($row3=$db->fetcharray()) {
$distrimail = $row3[0];
$distrmailok = $row3[1];
}
$db->query("SELECT email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDreseller") or die($db->error());
while ($row4=$db->fetcharray()) {
$dreselmail = $row4[0];
$reselmailok = $row4[1];
}
$db->query("SELECT email, mailings, companyName, firstName, lastName
FROM
tbl_contacts WHERE contactID = $endUserID") or die($db->error());
while ($row5=$db->fetcharray()) {
$endusmail = $row5[0];
$endusmailok = $row5[1];
$companyName = $row5[2];
$firstName = $row5[3];
$lastName = $row5[4];
}
//mail
$subject = "Maintenance Renewal: $maintenanceRefNumber";
$message = "Dear Madam,\nDear Sir,\n\nWe would like to inform you
that
your Maintenance contract for $productNaam $productType $productVersie
with
Maintenance Reference ID: $maintenanceRefNumber will expire on
$endDate.\n
Etc....";
$sendto = "";
// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
mail($sendto, $subject, $message);
//echo $distrimail."($maintenanceRefNumber distr), ";
}
if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselmail;
mail($sendto, $subject, $message);
//echo $dreselmail."($maintenanceRefNumber resel), ";
}
$sendto = $sendto.", ".$endusmail;
mail($sendto, $subject, $message);
//echo $endusmail."($maintenanceRefNumber endus)<br>";
echo "$maintenanceRefNumber - $myMaintenanceDate - $distrimail -
$dreselmail - $endusmail<br>";
//echo "$maintenanceRefNumber - $myMaintenanceDate<br>";
}
if (($myMaintenanceDate >= $myDatePlusOneBeginMonth) &&
($myMaintenanceDate
< $myDatePlusOneHalfMonth)) {
$db->query("SELECT tbl_product.productNaam,
tbl_product.productVersie,
tbl_product.productType FROM tbl_product, tbl_serials WHERE
(tbl_serials.serialID = $serialID) AND (tbl_serials.productID =
tbl_product.productID)") or die($db->error());
while ($row2=$db->fetcharray()) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}
$db->query("SELECT email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDdistributor") or die($db->error());
while ($row3=$db->fetcharray()) {
$distrimail = $row3[0];
$distrmailok = $row3[1];
}
$db->query("SELECT email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDreseller") or die($db->error());
while ($row4=$db->fetcharray()) {
$dreselmail = $row4[0];
$reselmailok = $row4[1];
}
$db->query("SELECT email, mailings, companyName, firstName, lastName
FROM
tbl_contacts WHERE contactID = $endUserID") or die($db->error());
while ($row5=$db->fetcharray()) {
$endusmail = $row5[0];
$endusmailok = $row5[1];
$companyName = $row5[2];
$firstName = $row5[3];
$lastName = $row5[4];
}
//mail
$subject = "Maintenance Renewal: $maintenanceRefNumber";
$message = "Dear Madam,\nDear Sir,\n\nWe would like to inform you
that
your Maintenance contract for $productNaam $productType $productVersie
with
Maintenance Reference ID: $maintenanceRefNumber will expire on
$endDate.\n
Etc...";
$sendto = "";
// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
//mail($sendto, $subject, $message);
//echo $distrimail."($maintenanceRefNumber +1/+2 distr), ";
}
if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselmail;
//mail($sendto, $subject, $message);
//echo $dreselmail."($maintenanceRefNumber +1/+2 resel), ";
}
if ($endusmailok == "1") {
$sendto = $sendto.", ".$endusmail;
mail($sendto, $subject, $message);
//echo $endusmail."($maintenanceRefNumber +1/+2 endus)<br>";
} else {
$sendtoOrder = "t...@test.com";
$message = "TESTTESTTESTETESTE\nPlease forward message to
ECU\n\nFollowing Maintenance needs to be renewed automatically:
$maintenanceRefNumber\nYour contact is $companyName\n$firstName
$lastName\n$endusmail.";
mail($sendtoOrder, $subject, $message);
mail($sendto, $subject, $message);
}
echo "$maintenanceRefNumber - $myMaintenanceDate - $distrimail -
$dreselmail - $endusmail<br>";
//echo "------ +1 ------ $maintenanceRefNumber -
$myMaintenanceDate<br>";
}
if (($myMaintenanceDate >= $myDatePlusTwoBeginMonth) &&
($myMaintenanceDate
< $myDatePlusTwoHalfMonth)) {
$db->query("SELECT tbl_product.productNaam,
tbl_product.productVersie,
tbl_product.productType FROM tbl_product, tbl_serials WHERE
(tbl_serials.serialID = $serialID) AND (tbl_serials.productID =
tbl_product.productID)") or die($db->error());
while ($row2=$db->fetcharray()) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}
$db->query("SELECT email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDdistributor") or die($db->error());
while ($row3=$db->fetcharray()) {
$distrimail = $row3[0];
$distrmailok = $row3[1];
}
$db->query("SELECT email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDreseller") or die($db->error());
while ($row4=$db->fetcharray()) {
$dreselmail = $row4[0];
$reselmailok = $row4[1];
}
$db->query("SELECT email, mailings, companyName, firstName, lastName
FROM
tbl_contacts WHERE contactID = $endUserID") or die($db->error());
while ($row5=$db->fetcharray()) {
$endusmail = $row5[0];
$endusmailok = $row5[1];
$companyName = $row5[2];
$firstName = $row5[3];
$lastName = $row5[4];
}
//mail
$subject = "Maintenance Renewal: $maintenanceRefNumber";
$message = "Dear Madam,\nDear Sir,\n\nWe would like to inform you
that
your Maintenance contract for $productNaam $productType $productVersie
with
Maintenance Reference ID: $maintenanceRefNumber will expire on
$endDate.\n
Etc...";
$sendto = "";
// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
//mail($sendto, $subject, $message);
//echo $distrimail."($maintenanceRefNumber +1/+2 distr), ";
}
if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselmail;
//mail($sendto, $subject, $message);
//echo $dreselmail."($maintenanceRefNumber +1/+2 resel), ";
}
if ($endusmailok == "1") {
$sendto = $sendto.", ".$endusmail;
mail($sendto, $subject, $message);
//echo $endusmail."($maintenanceRefNumber +1/+2 endus)<br>";
} else {
$sendtoOrder = t...@test.com";
$message = "TESTTESTTESTETESTE\nPlease forward message to
ECU\n\nFollowing Maintenance needs to be renewed automatically:
$maintenanceRefNumber\nYour contact is $companyName\n$firstName
$lastName\n$endusmail.";
mail($sendtoOrder, $subject, $message);
mail($sendto, $subject, $message);
}
echo "$maintenanceRefNumber - $myMaintenanceDate - $distrimail -
$dreselmail - $endusmail<br>";
//echo "------ +2 ------ $maintenanceRefNumber -
$myMaintenanceDate<br>";
}
}
?>
Oct 6 '05 #1
5 1767

Eric Culus wrote:
I seem to be having troubles with this page....
It's an automated mailing script...
Steps:
- system checks on x dates the variables linked to a maintenance
contract (query on db)
- when variable matches given element is queries the db again to
retrieve the contact data linked to the maintenance system
- I then sends an email to the different contacts linked to that
maintenance contract
- then the script schoul continue looping to the next maintenance
contract
BUT: somehow, the script stop after sending the first email.
Why?

<...SNIP 300 LINES OF CODE...>

Dude, NO-ONE is going to trawl through 300+ lines of your code to try
to figure out what's wrong.

Post a *minimal* test script, and we might be able to help...

--
Oli

Oct 6 '05 #2
I agree with Oli. If you give us a "short but complete" script it will
be sooo much easier. Read this article from John Skeet to know how to
make it...

http://www.yoda.arachsys.com/csharp/complete.html

All credit to that great guy.

Oct 6 '05 #3
Hope,

This' shorter...

<?

$db->open() or die($db->error());
$db->query("myquery") or die($db->error());
$i = 1;
while ($row=$db->fetcharray()) {
output db data

if (($myMaintenanceDate >= $mydateBeginMonth) && ($myMaintenanceDate <
$mydateHalfMonth)) {

$db->query("Start another query") or die($db->error());
while ($row2=$db->fetcharray()) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}

Etc... more queries until all data recovered

//mail
$subject = "mysubject";
$message = "mynessage";
$sendto = "myemail";

// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
mail($sendto, $subject, $message);
}

if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselmail;
mail($sendto, $subject, $message);
}

$sendto = $sendto.", ".$endusmail;
mail($sendto, $subject, $message);
}
}

loop until next matching record found....

?>
Oct 7 '05 #4
> <?

$db->open() or die($db->error());
$db->query("myquery") or die($db->error());
Don't know what's going on in your $db class, but do you have to assign the
result set to something?

e.g. $result=$db->query("Start another query") or die($db->error());
$i = 1;
while ($row=$db->fetcharray()) {
output db data

if (($myMaintenanceDate >= $mydateBeginMonth) && ($myMaintenanceDate <
$mydateHalfMonth)) {

$db->query("Start another query") or die($db->error());
Does this call to $db overwrite the result set you are looping on - the one
you initialise with query("myquery") ?

while ($row2=$db->fetcharray()) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}

Etc... more queries until all data recovered

//mail
$subject = "mysubject";
$message = "mynessage";
$sendto = "myemail";

// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
mail($sendto, $subject, $message);
}

if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselmail;
mail($sendto, $subject, $message);
}

$sendto = $sendto.", ".$endusmail;
mail($sendto, $subject, $message);
}
}

loop until next matching record found....

?>

Oct 10 '05 #5
>> $db->open() or die($db->error());
$db->query("myquery") or die($db->error());


Don't know what's going on in your $db class, but do you have to assign
the
result set to something?


No, the class is build in such a way that it is not necessary to use
"$result = "
$db->query("Start another query") or die($db->error());


Does this call to $db overwrite the result set you are looping on - the
one
you initialise with query("myquery") ?


This is a query request inside the first loop... simply pulling new data
from the db when a matching variable is found
"Mark Rees" <mr***@itsagoodprice.com> wrote in message
news:79******************@newsfe6-win.ntli.net...
<?

$db->open() or die($db->error());
$db->query("myquery") or die($db->error());


Don't know what's going on in your $db class, but do you have to assign
the
result set to something?

e.g. $result=$db->query("Start another query") or die($db->error());
$i = 1;
while ($row=$db->fetcharray()) {
output db data

if (($myMaintenanceDate >= $mydateBeginMonth) && ($myMaintenanceDate <
$mydateHalfMonth)) {

$db->query("Start another query") or die($db->error());


Does this call to $db overwrite the result set you are looping on - the
one
you initialise with query("myquery") ?

while ($row2=$db->fetcharray()) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}

Etc... more queries until all data recovered

//mail
$subject = "mysubject";
$message = "mynessage";
$sendto = "myemail";

// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
mail($sendto, $subject, $message);
}

if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselmail;
mail($sendto, $subject, $message);
}

$sendto = $sendto.", ".$endusmail;
mail($sendto, $subject, $message);
}
}

loop until next matching record found....

?>


Oct 11 '05 #6

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

Similar topics

2
by: Mike | last post by:
I need my textbox to work more smoothly with respect to line breaks. When I have data pulled from the database into a textbox there are hard line breaks at the end of each line (by definition how...
7
by: tshad | last post by:
I have been sending messages to myself from work that worked before and now all of my message only seem to be sending part of my messages. I get the first part of the message and then get...
2
by: Chris Schinzel | last post by:
Hi, I'm reading text from a html textarea field (standard wrap functionality, no value specified). If I display it via nl2br() (after html form submission), everything's ok. But if I send it via...
4
by: Bob | last post by:
This code snippet works fine (vs 2005) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim message As New MailMessage() Try...
2
by: Bandul | last post by:
Hi everyone I am trying to send a e-mail using the mail() function. Now i try to send more than one data from mysql database so i must use example $results=mysql_num_rows($result_query)...
0
by: Sheila | last post by:
I have set up a Word mail merge document of the type Directory which allows me to display all of the records on a single page rather than putting each record on a separate page. It uses a...
12
by: the other john | last post by:
I'm having trouble with spammers getting through my mail script. I've heard of FormMail for php but I need a solution for ASP. Any suggestions? I don't know how to stop these guys from using my...
1
Chrisjc
by: Chrisjc | last post by:
I have the following code... My issue is I have submited this form about ten times and have not recived and E-mail to the current address below any ideas? If someone could look this over and let...
0
by: anu b | last post by:
Now i am sending email to my friend using session variable... but my code is as below private bool SendEmail(string email) { try {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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:
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.