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("DbConn ect.class.php") ;
// -------------- calculate dates ------
$yearNow = date(Y);
$monthNow = date(m);
//$monthNow = 12;
$dayNow = date(d);
$now = date(Ymd);
$mydateBeginMon th = date("Ym01");
$mydateHalfMont h = 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;
}
$myDatePlusOneB eginMonth = $yearPlusOne."" .$monthPlusOne. "01";
$myDatePlusOneH alfMonth = $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;
}
$myDatePlusTwoB eginMonth = $yearPlusTwo."" .$monthPlusTwo. "01";
$myDatePlusTwoH alfMonth = $yearPlusTwo."" .$monthPlusTwo. "15";
echo $mydateBeginMon th." - ".$mydateHalfMo nth."<br><br><h r><br>";
echo $myDatePlusOneB eginMonth." -
".$myDatePlusOn eHalfMonth."<br ><br><hr><br> ";
echo $myDatePlusTwoB eginMonth." -
".$myDatePlusTw oHalfMonth."<br ><br><hr><br> ";
//*************** *************** *************** *************** *******
$db->open() or die($db->error());
$db->query("SELEC T maintenanceRefN umber, endDate, contactIDdistri butor,
contactIDresell er, serialID, endUserID FROM TBL_maintenance ORDER BY
endDate
ASC") or die($db->error());
$i = 1;
while ($row=$db->fetcharray() ) {
$maintenanceRef Number = $row[0];
$endDate = $row[1];
$contactIDdistr ibutor = $row[2];
$contactIDresel ler = $row[3];
$serialID = $row[4];
$endUserID = $row[5];
//echo "$i - $maintenanceRef Number - $endDate<br>";
list($day, $month, $year) = explode(".", $endDate);
$myMaintenanceD ate = $year."".$month ."".$day;
if (($myMaintenanc eDate >= $mydateBeginMon th) && ($myMaintenance Date <
$mydateHalfMont h)) {
// ----------------- GET DATA
----------------------------------------
//
-------------------------------------------------------------------
$db->query("SELEC T tbl_product.pro ductNaam,
tbl_product.pro ductVersie,
tbl_product.pro ductType FROM tbl_product, tbl_serials WHERE
(tbl_serials.se rialID = $serialID) AND (tbl_serials.pr oductID =
tbl_product.pro ductID)") or die($db->error());
while ($row2=$db->fetcharray() ) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDdistr ibutor") or die($db->error());
while ($row3=$db->fetcharray() ) {
$distrimail = $row3[0];
$distrmailok = $row3[1];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDresel ler") or die($db->error());
while ($row4=$db->fetcharray() ) {
$dreselmail = $row4[0];
$reselmailok = $row4[1];
}
$db->query("SELEC T 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 = "Maintenanc e Renewal: $maintenanceRef Number";
$message = "Dear Madam,\nDear Sir,\n\nWe would like to inform you
that
your Maintenance contract for $productNaam $productType $productVersie
with
Maintenance Reference ID: $maintenanceRef Number will expire on
$endDate.\n
Etc....";
$sendto = "";
// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
mail($sendto, $subject, $message);
//echo $distrimail."($ maintenanceRefN umber distr), ";
}
if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselma il;
mail($sendto, $subject, $message);
//echo $dreselmail."($ maintenanceRefN umber resel), ";
}
$sendto = $sendto.", ".$endusmai l;
mail($sendto, $subject, $message);
//echo $endusmail."($m aintenanceRefNu mber endus)<br>";
echo "$maintenanceRe fNumber - $myMaintenanceD ate - $distrimail -
$dreselmail - $endusmail<br>" ;
//echo "$maintenanceRe fNumber - $myMaintenanceD ate<br>";
}
if (($myMaintenanc eDate >= $myDatePlusOneB eginMonth) &&
($myMaintenance Date
< $myDatePlusOneH alfMonth)) {
$db->query("SELEC T tbl_product.pro ductNaam,
tbl_product.pro ductVersie,
tbl_product.pro ductType FROM tbl_product, tbl_serials WHERE
(tbl_serials.se rialID = $serialID) AND (tbl_serials.pr oductID =
tbl_product.pro ductID)") or die($db->error());
while ($row2=$db->fetcharray() ) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDdistr ibutor") or die($db->error());
while ($row3=$db->fetcharray() ) {
$distrimail = $row3[0];
$distrmailok = $row3[1];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDresel ler") or die($db->error());
while ($row4=$db->fetcharray() ) {
$dreselmail = $row4[0];
$reselmailok = $row4[1];
}
$db->query("SELEC T 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 = "Maintenanc e Renewal: $maintenanceRef Number";
$message = "Dear Madam,\nDear Sir,\n\nWe would like to inform you
that
your Maintenance contract for $productNaam $productType $productVersie
with
Maintenance Reference ID: $maintenanceRef Number will expire on
$endDate.\n
Etc...";
$sendto = "";
// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
//mail($sendto, $subject, $message);
//echo $distrimail."($ maintenanceRefN umber +1/+2 distr), ";
}
if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselma il;
//mail($sendto, $subject, $message);
//echo $dreselmail."($ maintenanceRefN umber +1/+2 resel), ";
}
if ($endusmailok == "1") {
$sendto = $sendto.", ".$endusmai l;
mail($sendto, $subject, $message);
//echo $endusmail."($m aintenanceRefNu mber +1/+2 endus)<br>";
} else {
$sendtoOrder = "t...@test.com" ;
$message = "TESTTESTTESTET ESTE\nPlease forward message to
ECU\n\nFollowin g Maintenance needs to be renewed automatically:
$maintenanceRef Number\nYour contact is $companyName\n$ firstName
$lastName\n$end usmail.";
mail($sendtoOrd er, $subject, $message);
mail($sendto, $subject, $message);
}
echo "$maintenanceRe fNumber - $myMaintenanceD ate - $distrimail -
$dreselmail - $endusmail<br>" ;
//echo "------ +1 ------ $maintenanceRef Number -
$myMaintenanceD ate<br>";
}
if (($myMaintenanc eDate >= $myDatePlusTwoB eginMonth) &&
($myMaintenance Date
< $myDatePlusTwoH alfMonth)) {
$db->query("SELEC T tbl_product.pro ductNaam,
tbl_product.pro ductVersie,
tbl_product.pro ductType FROM tbl_product, tbl_serials WHERE
(tbl_serials.se rialID = $serialID) AND (tbl_serials.pr oductID =
tbl_product.pro ductID)") or die($db->error());
while ($row2=$db->fetcharray() ) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDdistr ibutor") or die($db->error());
while ($row3=$db->fetcharray() ) {
$distrimail = $row3[0];
$distrmailok = $row3[1];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDresel ler") or die($db->error());
while ($row4=$db->fetcharray() ) {
$dreselmail = $row4[0];
$reselmailok = $row4[1];
}
$db->query("SELEC T 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 = "Maintenanc e Renewal: $maintenanceRef Number";
$message = "Dear Madam,\nDear Sir,\n\nWe would like to inform you
that
your Maintenance contract for $productNaam $productType $productVersie
with
Maintenance Reference ID: $maintenanceRef Number will expire on
$endDate.\n
Etc...";
$sendto = "";
// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
//mail($sendto, $subject, $message);
//echo $distrimail."($ maintenanceRefN umber +1/+2 distr), ";
}
if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselma il;
//mail($sendto, $subject, $message);
//echo $dreselmail."($ maintenanceRefN umber +1/+2 resel), ";
}
if ($endusmailok == "1") {
$sendto = $sendto.", ".$endusmai l;
mail($sendto, $subject, $message);
//echo $endusmail."($m aintenanceRefNu mber +1/+2 endus)<br>";
} else {
$sendtoOrder = t...@test.com";
$message = "TESTTESTTESTET ESTE\nPlease forward message to
ECU\n\nFollowin g Maintenance needs to be renewed automatically:
$maintenanceRef Number\nYour contact is $companyName\n$ firstName
$lastName\n$end usmail.";
mail($sendtoOrd er, $subject, $message);
mail($sendto, $subject, $message);
}
echo "$maintenanceRe fNumber - $myMaintenanceD ate - $distrimail -
$dreselmail - $endusmail<br>" ;
//echo "------ +2 ------ $maintenanceRef Number -
$myMaintenanceD ate<br>";
}
}
?>
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("DbConn ect.class.php") ;
// -------------- calculate dates ------
$yearNow = date(Y);
$monthNow = date(m);
//$monthNow = 12;
$dayNow = date(d);
$now = date(Ymd);
$mydateBeginMon th = date("Ym01");
$mydateHalfMont h = 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;
}
$myDatePlusOneB eginMonth = $yearPlusOne."" .$monthPlusOne. "01";
$myDatePlusOneH alfMonth = $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;
}
$myDatePlusTwoB eginMonth = $yearPlusTwo."" .$monthPlusTwo. "01";
$myDatePlusTwoH alfMonth = $yearPlusTwo."" .$monthPlusTwo. "15";
echo $mydateBeginMon th." - ".$mydateHalfMo nth."<br><br><h r><br>";
echo $myDatePlusOneB eginMonth." -
".$myDatePlusOn eHalfMonth."<br ><br><hr><br> ";
echo $myDatePlusTwoB eginMonth." -
".$myDatePlusTw oHalfMonth."<br ><br><hr><br> ";
//*************** *************** *************** *************** *******
$db->open() or die($db->error());
$db->query("SELEC T maintenanceRefN umber, endDate, contactIDdistri butor,
contactIDresell er, serialID, endUserID FROM TBL_maintenance ORDER BY
endDate
ASC") or die($db->error());
$i = 1;
while ($row=$db->fetcharray() ) {
$maintenanceRef Number = $row[0];
$endDate = $row[1];
$contactIDdistr ibutor = $row[2];
$contactIDresel ler = $row[3];
$serialID = $row[4];
$endUserID = $row[5];
//echo "$i - $maintenanceRef Number - $endDate<br>";
list($day, $month, $year) = explode(".", $endDate);
$myMaintenanceD ate = $year."".$month ."".$day;
if (($myMaintenanc eDate >= $mydateBeginMon th) && ($myMaintenance Date <
$mydateHalfMont h)) {
// ----------------- GET DATA
----------------------------------------
//
-------------------------------------------------------------------
$db->query("SELEC T tbl_product.pro ductNaam,
tbl_product.pro ductVersie,
tbl_product.pro ductType FROM tbl_product, tbl_serials WHERE
(tbl_serials.se rialID = $serialID) AND (tbl_serials.pr oductID =
tbl_product.pro ductID)") or die($db->error());
while ($row2=$db->fetcharray() ) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDdistr ibutor") or die($db->error());
while ($row3=$db->fetcharray() ) {
$distrimail = $row3[0];
$distrmailok = $row3[1];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDresel ler") or die($db->error());
while ($row4=$db->fetcharray() ) {
$dreselmail = $row4[0];
$reselmailok = $row4[1];
}
$db->query("SELEC T 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];
}
$subject = "Maintenanc e Renewal: $maintenanceRef Number";
$message = "Dear Madam,\nDear Sir,\n\nWe would like to inform you
that
your Maintenance contract for $productNaam $productType $productVersie
with
Maintenance Reference ID: $maintenanceRef Number will expire on
$endDate.\n
Etc....";
$sendto = "";
// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
mail($sendto, $subject, $message);
//echo $distrimail."($ maintenanceRefN umber distr), ";
}
if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselma il;
mail($sendto, $subject, $message);
//echo $dreselmail."($ maintenanceRefN umber resel), ";
}
$sendto = $sendto.", ".$endusmai l;
mail($sendto, $subject, $message);
//echo $endusmail."($m aintenanceRefNu mber endus)<br>";
echo "$maintenanceRe fNumber - $myMaintenanceD ate - $distrimail -
$dreselmail - $endusmail<br>" ;
//echo "$maintenanceRe fNumber - $myMaintenanceD ate<br>";
}
if (($myMaintenanc eDate >= $myDatePlusOneB eginMonth) &&
($myMaintenance Date
< $myDatePlusOneH alfMonth)) {
$db->query("SELEC T tbl_product.pro ductNaam,
tbl_product.pro ductVersie,
tbl_product.pro ductType FROM tbl_product, tbl_serials WHERE
(tbl_serials.se rialID = $serialID) AND (tbl_serials.pr oductID =
tbl_product.pro ductID)") or die($db->error());
while ($row2=$db->fetcharray() ) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDdistr ibutor") or die($db->error());
while ($row3=$db->fetcharray() ) {
$distrimail = $row3[0];
$distrmailok = $row3[1];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDresel ler") or die($db->error());
while ($row4=$db->fetcharray() ) {
$dreselmail = $row4[0];
$reselmailok = $row4[1];
}
$db->query("SELEC T 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];
}
$subject = "Maintenanc e Renewal: $maintenanceRef Number";
$message = "Dear Madam,\nDear Sir,\n\nWe would like to inform you
that
your Maintenance contract for $productNaam $productType $productVersie
with
Maintenance Reference ID: $maintenanceRef Number will expire on
$endDate.\n
Etc...";
$sendto = "";
// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
//mail($sendto, $subject, $message);
//echo $distrimail."($ maintenanceRefN umber +1/+2 distr), ";
}
if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselma il;
//mail($sendto, $subject, $message);
//echo $dreselmail."($ maintenanceRefN umber +1/+2 resel), ";
}
if ($endusmailok == "1") {
$sendto = $sendto.", ".$endusmai l;
mail($sendto, $subject, $message);
//echo $endusmail."($m aintenanceRefNu mber +1/+2 endus)<br>";
} else {
$sendtoOrder = "t...@test.com" ;
$message = "TESTTESTTESTET ESTE\nPlease forward message to
ECU\n\nFollowin g Maintenance needs to be renewed automatically:
$maintenanceRef Number\nYour contact is $companyName\n$ firstName
$lastName\n$end usmail.";
mail($sendtoOrd er, $subject, $message);
mail($sendto, $subject, $message);
}
echo "$maintenanceRe fNumber - $myMaintenanceD ate - $distrimail -
$dreselmail - $endusmail<br>" ;
//echo "------ +1 ------ $maintenanceRef Number -
$myMaintenanceD ate<br>";
}
if (($myMaintenanc eDate >= $myDatePlusTwoB eginMonth) &&
($myMaintenance Date
< $myDatePlusTwoH alfMonth)) {
$db->query("SELEC T tbl_product.pro ductNaam,
tbl_product.pro ductVersie,
tbl_product.pro ductType FROM tbl_product, tbl_serials WHERE
(tbl_serials.se rialID = $serialID) AND (tbl_serials.pr oductID =
tbl_product.pro ductID)") or die($db->error());
while ($row2=$db->fetcharray() ) {
$productNaam = $row2[0];
$productVersie = $row2[1];
$productType = $row2[2];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDdistr ibutor") or die($db->error());
while ($row3=$db->fetcharray() ) {
$distrimail = $row3[0];
$distrmailok = $row3[1];
}
$db->query("SELEC T email, mailings FROM tbl_contacts WHERE contactID
=
$contactIDresel ler") or die($db->error());
while ($row4=$db->fetcharray() ) {
$dreselmail = $row4[0];
$reselmailok = $row4[1];
}
$db->query("SELEC T 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];
}
$subject = "Maintenanc e Renewal: $maintenanceRef Number";
$message = "Dear Madam,\nDear Sir,\n\nWe would like to inform you
that
your Maintenance contract for $productNaam $productType $productVersie
with
Maintenance Reference ID: $maintenanceRef Number will expire on
$endDate.\n
Etc...";
$sendto = "";
// send email
if ($distrmailok == "1") {
$sendto = $distrimail;
//mail($sendto, $subject, $message);
//echo $distrimail."($ maintenanceRefN umber +1/+2 distr), ";
}
if ($reselmailok == "1") {
$sendto = $sendto.", ".$dreselma il;
//mail($sendto, $subject, $message);
//echo $dreselmail."($ maintenanceRefN umber +1/+2 resel), ";
}
if ($endusmailok == "1") {
$sendto = $sendto.", ".$endusmai l;
mail($sendto, $subject, $message);
//echo $endusmail."($m aintenanceRefNu mber +1/+2 endus)<br>";
} else {
$sendtoOrder = t...@test.com";
$message = "TESTTESTTESTET ESTE\nPlease forward message to
ECU\n\nFollowin g Maintenance needs to be renewed automatically:
$maintenanceRef Number\nYour contact is $companyName\n$ firstName
$lastName\n$end usmail.";
mail($sendtoOrd er, $subject, $message);
mail($sendto, $subject, $message);
}
echo "$maintenanceRe fNumber - $myMaintenanceD ate - $distrimail -
$dreselmail - $endusmail<br>" ;
//echo "------ +2 ------ $maintenanceRef Number -
$myMaintenanceD ate<br>";
}
}
?>
Comment