You are here: mail () breaks loop « PHP Programming Language « IT news, forums, messages
mail () breaks loop

Posted by Eric Culus on 10/06/05 15:44

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>";
}


}


?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация