close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Sending to list generated from MySQLi recordset

Thread began 5/08/2017 11:46 am by Steve | Last modified 10/02/2017 2:42 pm by Steve | 198 views | 20 replies

georgina_barrett_187762

I am working on a different project that does 3 things.
1. inserts a single record into a table
2. inserts multiple records into a table
3. Sends an email to multiple recipients based on a recordset value

1 & 2 are working fine, however the email is not sending. it is redirecting ok but no email gets sent.
I added
<?php
session_start();
var_dump($_SESSION);
?>
To the redirect page and this is the output:
array(18) { ["WA_AUTH_AdminLogin"]=> array(5) { [0]=> string(13) "AdminUsername" [1]=> string(13) "AdminPassword" [2]=> string(15) "AdminLoginLevel" [3]=> string(10) "AdminAgent" [4]=> string(10) "AdminEmail" } ["AdminUsername"]=> string(8) "Hidden" ["AdminPassword"]=> string(7) "password" ["AdminLoginLevel"]=> int(1) ["AdminAgent"]=> string(8) "Georgina" ["AdminEmail"]=> string(30) "georgina@*******.co.uk" ["WAENCRYPTEDRETURNUSED"]=> bool(false) ["WAENCRYPTEDRETURNSUCCESS"]=> bool(false) ["WA_FAIL_AdminLogin"]=> string(109) "/admin/index.php?accesscheck=%2Fadmin%2Fdemo%2Findex.php%3Faccesscheck%3D%252Fadmin%252Fmanagerlists.php%253F" ["MailshotID"]=> int(9) ["waue_email_mailshot_1_Status"]=> NULL ["waue_email_mailshot_1_Index"]=> NULL ["waue_email_mailshot_1_From"]=> NULL ["waue_email_mailshot_1_To"]=> NULL ["waue_email_mailshot_1_Subject"]=> NULL ["waue_email_mailshot_1_Body"]=> NULL ["waue_email_mailshot_1_Header"]=> NULL ["waue_email_mailshot_1_Log"]=> NULL }

The page code is:
<?php require_once('../../Connections/horizon_i.php'); ?>
<?php require_once("../../webassist/ckeditor/ckeditor.php"); ?>
<?php require_once( "../../webassist/security_assist/helper_php.php" ); ?>
<?php require_once('../../webassist/mysqli/rsobj.php'); ?>
<?php require_once("../../webassist/database_management/wa_appbuilder_php.php"); ?>
<?php require_once('../../webassist/mysqli/queryobj.php'); ?>
<?php
if (!WA_Auth_RulePasses("Manager")){
WA_Auth_RestrictAccess("../../managerlogin.php");
}?>
<?php
$client = new WA_MySQLi_RS("client",$horizon_i,0);
$client->setQuery("SELECT Client.ID, Client.Title, Client.FirstName, Client.Surname, Client.Email, Client.Email2, ClientProduct.Product, Client.Leadsource FROM Client JOIN ClientProduct ON ClientProduct.ClientID=Client.ID WHERE ClientProduct.Product IN (?) AND NOT EXISTS (SELECT c.ID FROM Client c JOIN ClientProduct cp ON cp.ClientID=c.ID WHERE Client.ID=c.ID AND cp.Product IN (?))");
$client->bindParam("sl", "".implode(",",$_POST['addproduct']) ."", "-1"); //colname
$client->bindParam("sl", "".implode(",",$_POST['removeproduct']) ."", "-1"); //colname1
$client->execute();
?>
<?php
$client1 = new WA_MySQLi_RS("client1",$horizon_i,0);
$client1->setQuery("SELECT Client.ID, Client.Title, Client.FirstName, Client.Surname, Client.Email, Client.Email2, ClientProduct.Product, Client.Leadsource FROM Client JOIN ClientProduct ON ClientProduct.ClientID=Client.ID WHERE ClientProduct.Product IN (?) AND NOT EXISTS (SELECT c.ID FROM Client c JOIN ClientProduct cp ON cp.ClientID=c.ID WHERE Client.ID=c.ID AND cp.Product IN (?))");
$client1->bindParam("sl", "".implode(",",$_POST['addproduct']) ."", "-1"); //colname
$client1->bindParam("sl", "".implode(",",$_POST['removeproduct']) ."", "-1"); //colname1
$client1->execute();?>
<?php
$client2 = new WA_MySQLi_RS("client2",$horizon_i,0);
$client2->setQuery("SELECT Client.Email FROM Client JOIN ClientProduct ON ClientProduct.ClientID=Client.ID WHERE ClientProduct.Product IN (?) AND NOT EXISTS (SELECT c.ID FROM Client c JOIN ClientProduct cp ON cp.ClientID=c.ID WHERE Client.ID=c.ID AND cp.Product IN (?))");
$client2->bindParam("text list", "".implode(",",$_POST['addproduct']) ."", "-1"); //colname
$client2->bindParam("text list", "".implode(",",$_POST['removeproduct']) ."", "-1"); //colname1
$client2->execute();
?>
<?php
if ((isset($_POST["submit"]) || isset($_POST["submit_x"])) && isset($_POST["subject"])) {
$InsertQuery = new WA_MySQLi_Query($horizon_i);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "EmailMailshots";
$InsertQuery->bindColumn("SubjectLine", "s", "".((isset($_POST["subject"]))?$_POST["subject"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("MailshotText", "s", "".((isset($_POST["editorField"]))?$_POST["editorField"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("SentBy", "s", "".((isset($_POST["EmailFrom"]))?$_POST["EmailFrom"]:"") ."", "WA_DEFAULT");
$InsertQuery->saveInSession("MailshotID");
$InsertQuery->execute();
$InsertGoTo = "";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
if (isset($_POST["submit"]) || isset($_POST["submit_x"])) {
for ($x=0; $x<sizeof($_POST['ClientID']); $x++) {
$InsertQuery = new WA_MySQLi_Query($horizon_i);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "EmailMailshotSent";
$InsertQuery->bindColumn("ClientID", "i", "".($_POST['ClientID'][$x]) ."", "WA_DEFAULT");
$InsertQuery->bindColumn("MailshotID", "i", "".$_SESSION['MailshotID'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("SubjectLine", "s", "".((isset($_POST["subject"]))?$_POST["subject"]:"") ."", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}}
?>
<?php require_once("../../webassist/email/mail_php.php"); ?>
<?php require_once("../../webassist/email/mailformatting_php.php"); ?>
<?php
if ((isset($_POST["submit"]) || isset($_POST["submit_x"])) && isset($_POST["subject"])) {
//WA Universal Email object="mail"
@session_write_close();
@set_time_limit(0);
$EmailRef = "waue_email_mailshot_1";
$BurstSize = 200;
$BurstTime = 1;
$WaitTime = 1;
$GoToPage = "search_mailshots.php";
$RecipArray = array();
$StartBurst = time();
$LoopCount = 0;
$TotalEmails = 0;
$RecipIndex = 0;
// build up recipients array
$CurIndex = sizeof($RecipArray);
$RecipArray[$CurIndex] = array();
while(!$client2->atEnd()) {
$RecipArray[$CurIndex ][] = "".($client2->getColumnVal("Email")) .""; $client2->moveNext();
}
$TotalEmails += sizeof($RecipArray[$CurIndex]);
$RealWait = ($WaitTime<0.25)?0.25:($WaitTime+0.1);
$TimeTracker = Array();
$TotalBursts = floor($TotalEmails/$BurstSize);
$AfterBursts = $TotalEmails % $BurstSize;
$TimeRemaining = ($TotalBursts * $BurstTime) + ($AfterBursts*$RealWait);
if ($TimeRemaining < ($TotalEmails*$RealWait) ) {
$TimeRemaining = $TotalEmails*$RealWait;
}
writeUEProgress($EmailRef,0,$TotalEmails,$TimeRemaining);
while ($RecipIndex < sizeof($RecipArray)) {
$EnteredValue = is_string($RecipArray[$RecipIndex][0]);
$CurIndex = 0;
while (($EnteredValue && $CurIndex < sizeof($RecipArray[$RecipIndex])) || (!$EnteredValue && $RecipArray[$RecipIndex][0])) {
$starttime = microtime_float();
if ($EnteredValue) {
$RecipientEmail = $RecipArray[$RecipIndex][$CurIndex];
} else {
$RecipientEmail = $RecipArray[$RecipIndex][0][$RecipArray[$RecipIndex][2]];
}
$EmailsRemaining = ($TotalEmails- $LoopCount);
$BurstsRemaining = ceil(($EmailsRemaining-$AfterBursts)/$BurstSize);
$IntoBurst = ($EmailsRemaining-$AfterBursts) % $BurstSize;
if ($AfterBursts<$EmailsRemaining) $IntoBurst = 0;
$TimeRemaining = ($BurstsRemaining * $BurstTime * 60) + ((($AfterBursts<$EmailsRemaining)?$AfterBursts:$EmailsRemaining)*$RealWait) - (($AfterBursts>$EmailsRemaining)?0:($IntoBurst*$RealWait));
if ($TimeRemaining < ($EmailsRemaining*$RealWait) ) {
$TimeRemaining = $EmailsRemaining*$RealWait;
}
$CurIndex ++;
$LoopCount ++;
writeUEProgress($EmailRef,$LoopCount,$TotalEmails,round($TimeRemaining));
wa_sleep($WaitTime);
include("../../webassist/email/waue_email_mailshot_1.php");
$endtime = microtime_float();
$TimeTracker[] =$endtime - $starttime;
$RealWait = array_sum($TimeTracker)/sizeof($TimeTracker);
if ($LoopCount % $BurstSize == 0 && $CurIndex < sizeof($RecipArray[$RecipIndex])) {
$TimePassed = (time() - $StartBurst);
if ($TimePassed < ($BurstTime*60)) {
$WaitBurst = ($BurstTime*60) -$TimePassed;
wa_sleep($WaitBurst);
}
else {
$TimeRemaining = ($TotalEmails- $LoopCount)*$RealWait;
}
$StartBurst = time();
}
if (!$EnteredValue) {
$RecipArray[$RecipIndex][0] = mysql_fetch_assoc($RecipArray[$RecipIndex][1]);
}
}
$RecipIndex ++;
}
@session_start();
$_SESSION[$EmailRef."_Status"] = $GLOBALS[$EmailRef."_Status"];
$_SESSION[$EmailRef."_Index"] = $GLOBALS[$EmailRef."_Index"];
$_SESSION[$EmailRef."_From"] = $GLOBALS[$EmailRef."_From"];
$_SESSION[$EmailRef."_To"] = $GLOBALS[$EmailRef."_To"];
$_SESSION[$EmailRef."_Subject"] = $GLOBALS[$EmailRef."_Subject"];
$_SESSION[$EmailRef."_Body"] = $GLOBALS[$EmailRef."_Body"];
$_SESSION[$EmailRef."_Header"] = $GLOBALS[$EmailRef."_Header"];
$_SESSION[$EmailRef."_Log"] = $GLOBALS[$EmailRef."_Log"];
if (function_exists("rel2abs")) $GoToPage = $GoToPage?rel2abs($GoToPage,dirname(__FILE__)):"";
if ($GoToPage!="") {
header("Location: ".$GoToPage);
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title><link href="../style-conf.css" rel="stylesheet" type="text/css" />
</head>
<body bgcolor="#EAEAEA" style="background: #EAEAEA">
<div class="container">
<div class="containerinner">

<?php include('../../inc/nav.php'); ?>
</div>
<div class="containerinner">
<table width="100%" align="center" cellpadding="10" cellspacing="10" style="max-width:900px; margin:0 auto; background-color:#FFF">
<tr><td>
<img src="http://www.co.uk/images/email-header.jpg" alt=""/>
</td>
</tr>
<tr>
<td><form action="" method="post" enctype="multipart/form-data" name="form1">

<p>Send Email to: <?php echo $client->TotalRows ?> clients, from <?php echo($_SESSION['AdminEmail']); ?>
<input name="EmailFrom" type="hidden" id="EmailFrom" value="<?php echo($_SESSION['AdminEmail']); ?>">
<?php
while(!$client->atEnd()) {
?>
<input name="ClientID[]" type="hidden" id="ClientID[]" value="<?php echo($client->getColumnVal("ID")); ?>">
<?php
$client->moveNext();
}
$client->moveFirst(); //return RS to first record
?>
<br>
<?php if ($_SESSION['AdminEmail'] !='') { // Show if mysqli recordset not empty ?>
<input name="submit" type="submit" class="submitbutton2" id="submit" value="Submit">
<?php } // Show if mysqli recordset not empty ?>
</p>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<th valign="top">Subject: </th>
<td valign="top" nowrap="nowrap"><input name="subject" type="text" class="full" id="subject"></td>
</tr>
</table>



<?php
// The initial value to be displayed in the editor.
$CKEditor_initialValue = "";
$CKEditor = new CKEditor();
$CKEditor->basePath = "../../webassist/ckeditor/";
$CKEditor_config = array();
$CKEditor_config["wa_preset_name"] = "Normal";
$CKEditor_config["wa_preset_file"] = "Normal.xml";
$CKEditor_config["width"] = "100%";
$CKEditor_config["height"] = "500px";
$CKEditor_config["dialog_startupFocusTab"] = false;
$CKEditor_config["fullPage"] = false;
$CKEditor_config["tabSpaces"] = 4;
$CKEditor_config["toolbar"] = array(
array( 'Bold','Italic','Underline'),
array( 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'),
array( 'NumberedList','BulletedList','-','Outdent','Indent'),
array( 'FontName','FontSize'),
array( 'TextColor'));
$CKEditor_config["contentsLangDirection"] = "ltr";
$CKEditor_config["entities"] = false;
$CKEditor_config["pasteFromWordRemoveFontStyles"] = false;
$CKEditor_config["pasteFromWordRemoveStyles"] = false;
$CKEditor->editor("editorField", $CKEditor_initialValue, $CKEditor_config);
?>
</form>
</p> </td>
</tr>
<tr>
<td><table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td align="center" nowrap style="background: #002040; color:#FFF; font-size:1.3em;">freephone &nbsp;&nbsp;&nbsp;<a href="http://www.co.uk" style="color:#FFF; text-decoration:none">www.co.uk</a></td>
</tr>
</table></td>
</tr>
</table>
</div></div></div>
</body>
</html>

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...