close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

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 Ray Borduin | 176 views | 20 replies |

Steve

Sending to list generated from MySQLi recordset

Does the current Universal Email work with MySQLi ?

Need to know if I need hack the behaviour or fall back to a non mysqli recordset or as prior suggested, loop the behaviour???

Looks like the value is properly setting in the behaviour but would appreciate some clarifications on if this will work. Tests show only one of the target emails showing up but not sure if my mail server is blocking or if the Behaviour is not completing the loop of recipeients...?

<?php
if (($_SERVER["REQUEST_METHOD"] == "POST")) {
//WA Universal Email object="mail"
@session_write_close();
@set_time_limit(0);
$EmailRef = "waue_email-blast-simple_1";
$BurstSize = 200;
$BurstTime = 1;
$WaitTime = 1;
$GoToPage = "email-blast-simple.php?sent=1";
$RecipArray = array();
$StartBurst = time();
$LoopCount = 0;
$TotalEmails = 0;
$RecipIndex = 0;
// build up recipients array
$CurIndex = sizeof($RecipArray);
$RecipArray[$CurIndex] = array();
$RecipArray[$CurIndex ][] = "".($emailTargets->getColumnVal("eMail")) ."";
$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;
}



What about debugging? Anything built in or any help on this level also?

Sign in to reply to this post

Ray BorduinWebAssist

This would only send to the first record returned, not the entire list. You would have to hand edit it to get it to work since mysqli recordset lists isn't directly supported.

Just update this line:

$RecipArray[$CurIndex ][] = "".($emailTargets->getColumnVal("eMail")) ."";

to:

while (!$emailTargets->atEnd()) {
$RecipArray[$CurIndex ][] = "".($emailTargets->getColumnVal("eMail")) ."";
$emailTargets->moveNext();
}

The email information is saved in the session to help with debugging. You should be able to use:
<?php
session_start();
var_dump($_SESSION);
?>

on the page after sending the email to see more information about what was sent and if it returns an error.

Sign in to reply to this post

Steve

Thanks Ray!

That works just fine. You should get that in a new release as it is very beneficial to the Behaviour.

I had to limit my mailing to only 10 addresses at a time otherwise there was an error, likely due to server timeout.

Is there untapped goodness in the email behaviour?

For instance:

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-blast-simple_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 ++;
}


Burst, loops, don't these set the a delay when sending to multiple recipients?

Sign in to reply to this post

Ray BorduinWebAssist

Yes, you can set delays when doing mass mailings to prevent from overburden on your SMTP server and in order to comply with hosting companies restrictions.

The line:
@set_time_limit(0);

Should allow the scripts to run for as long as they need to, but some shared servers block access to that function because it allows a page to run forever and potentially burden other sites running on the same box. That usually isn't a problem with a dedicated server.

Sign in to reply to this post

Steve

Thanks Ray!

Sign in to reply to this post

Steve

>> @set_time_limit(0);

This did not work as I still get Timeouts

I run my own Dedicated Server so have full control on this. Any details on what needs to be reviewed to see why the set_time_limit does not seem to be working?

I have another large list of recipients to send to today and it would be nice if Universal Email could be used to achieve the goal.

Sign in to reply to this post

Ray BorduinWebAssist

set_time_limit() won't work when php is running in safe mode. Turn off safe mode in your php.ini file and it should start working.

Sign in to reply to this post

georgina_barrett_187762

Same Issue but getting an error

I have the same problem in that I need to send an email to multiple addresses from a MySQLi recordset. I have applied the code you suggested above but I get this error.
Warning: mysql_select_db() expects parameter 2 to be resource, object given in /home/horizontravelco/public_html/webassist/email/mailformatting_php.php on line 56.

This is my code

<?php
if (("" == "")) {
//WA Universal Email object="mail"
@session_write_close();
@set_time_limit(0);
$EmailRef = "waue_noupdate5_1";
$BurstSize = 200;
$BurstTime = 1;
$WaitTime = 1;
$GoToPage = "";
$RecipArray = array();
$StartBurst = time();
$LoopCount = 0;
$TotalEmails = 0;
$RecipIndex = 0;
// build up recipients array
$CurIndex = sizeof($RecipArray);
$RecipArray[$CurIndex] = array();
while(!$lastupdated->atEnd()) {
$RecipArray[$CurIndex ][] = "".($lastupdated->getColumnVal("NotificationEmail")) .""; $lastupdated->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_noupdate5_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);
}
}
?>

Warning: mysql_query() expects parameter 2 to be resource, object given in /home/horizontravelco/public_html/webassist/email/mailformatting_php.php on line 94

Sign in to reply to this post

Steve

""Warning: mysql_query() expects parameter 2 to be resource""

It's likely the issue is in your query rather than the email object.

Sign in to reply to this post

Ray BorduinWebAssist

I'd need to look at line 56, but this error implies that your database connection isn't working or your code is in the wrong order on the page and you have a recordset above the connection.

Sign in to reply to this post
loading

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...