Odyssey
aSendEmail.data
1 <?php
2 require_once(dirname(__FILE__) . "/cu_notify.data"); // Need the call to read from Amazon.
3 
4 /**
5  * function GetSelectArray()
6  * @return the valid keys for things that can be selected.
7  */
8 function GetSelectArray() {
9  // #3044: billPay option is no longer available
10  // If necessary, we will need to use perms on profile
11  // --------------------
12  return [
13  "all",
14  "withE",
15  //"withBP",
16  "withoutE",
17  "withText"
18  ];
19 }
20 
21 /**
22  * function GetTagList()
23  * @return list of HTML tags that TinyMCE allows. All HTML tags are stripped out of the email body that don't relate to this.
24  */
25 function GetTagList() {
26  return "<blockquote><p><a><strong><em><span><img><ul><li><ol>";
27 }
28 
29 /**
30  * function RemoveTemplate($dbh, $Cu, $Cn, $templateId)
31  * Removes the email template
32  *
33  * @param integer $dbh -- the database connection
34  * @param string $Cu -- the credit union
35  * @param string $Cn -- the logged in user
36  * @param number $templateId -- the id of the template to remove
37  *
38  * @return "status" -- "000" if successful, nonzero otherwise
39  * @return "error" -- empty string if successful, nonempty otherwise
40  * @return "data"."templateDDL" -- a list of data for the template dropdownlist
41  * @return "info" -- message to the user when successful
42  * @return "operation" -- the operation to distinguish afterwards
43  */
44 function RemoveTemplate($dbh, $Cu, $Cn, $templateId) {
45  try {
46  if ($templateId == 0) {
47  throw new exception("Template Id is required.", 1);
48  }
49  $updateTable = array("_action" => "delete", "tmpl_id" => $templateId);
50  $updateTable = array("cuadmemailtmpl" => array($updateTable));
51 
52  $sql = "select email from cuadminusers where user_name = '$Cn' and cu = '$Cu'";
53  if (($sth = db_query($sql, $dbh)) !== false) {
54  $email = db_fetch_row($sth)[0];
55  } else {
56  throw new exception("Email query failed.", 2);
57  }
58 
59  if (DataAdminTableUpdate($dbh, array("cu" => $Cu), $updateTable, $Cn, "RM_ETEMPL", "broadcastEmails.prg", "A", "Email Template Deleted", $Cn, $email,
60  trim($_SERVER["REMOTE_ADDR"])) === false) {
61  throw new exception("Update failed.", 3);
62  }
63 
64  $results = ReadTemplate($dbh, $Cu);
65  if ($results ["status"] !== "000") {
66  throw new exception ("Read Template failed.", 4);
67  }
68  $templateDDL = $results["data"]["templateDDL"];
69 
70  $returnArray = array("status" => "000", "error" => "", "data" => array("templateDDL" => $templateDDL), "info" => "Template was deleted successfully.", "operation" => "removeTemplate");
71  } catch(exception $e) {
72  $returnArray = array("status" => $e->getCode(), "error" => $e->getMessage(), "data" => array("templateDDL" => array()), "operation" => "removeTemplate");
73  }
74  return $returnArray;
75 }
76 
77 /**
78  * function SaveTemplate($dbh, $Cu, $Cn, $testAddress, $body, $fromEmail, $fromName, $subject, $optin, $select, $templateName, $templateId)
79  * Saves the email template (or creates one if the template is set to "(none)")
80  *
81  * @param integer $dbh -- the database connection
82  * @param string $Cu -- the credit union
83  * @param string $Cn -- the logged in user
84  * @param string $testAddress -- the test address to send preview to
85  * @param string $body -- the body of the email
86  * @param string $fromEmail -- the email to send email from
87  * @param string $fromName -- the name of the from email
88  * @param string $subject -- the subject of the email
89  * @param string $optin -- does the user have to opt in to see the email?
90  * @param string $select -- the value of the select option (all members, members with E-statements, etc.)
91  * @param string $templateName -- the name of the template
92  * @param number $templateId -- the id of the template. If it is zero, then create a template.
93  *
94  * @return "status" -- "000" if successful, nonzero otherwise
95  * @return "error" -- empty string if successful, nonempty otherwise
96  * @return "data"."templateDDL" -- a list of data for the template dropdownlist
97  * @return "data"."templateId" -- set the template dropdownlist to this template
98  * @return "info" -- message to the user when successful
99  * @return "operation" -- the operation to distinguish afterwards
100  */
101 function SaveTemplate($dbh, $Cu, $Cn, $testAddress, $body, $fromEmail, $fromName, $subject, $optin, $select, $templateName, $templateId) {
102  try {
103  $selectArray = GetSelectArray();
104  $tagList = GetTagList();
105  $results = _ValidateTemplate ($testAddress, $fromEmail, $subject, $select, $templateName, $selectArray, $optin);
106  if ($results ["status"] !== "000") {
107  throw new exception ($results ["error"], 18);
108  }
109 
110  $fromEmail = strtolower(trim($fromEmail));
111 
112  $body = strip_tags($body, $tagList); // Remove tags that aren't "approved."
113 
114  // Saved as a small int so save the index of the array.
115  $intSelect = array_flip($selectArray);
116  $intSelect = $intSelect[$select];
117  $updateTable = array("cu" => $Cu,
118  "tmpl_email" => $fromEmail,
119  "tmpl_email_name" => $fromName,
120  "tmpl_subject" => $subject,
121  "tmpl_message" => $body,
122  "tmpl_opt_mailto" => $optin == "Y" ? 1 : 0,
123  "tmpl_opt_mbr" => $intSelect,
124  "tmpl_lastmodified" => DBTIMESTAMP_USENOW,
125  "tmpl_name" => $templateName);
126 
127  if ($templateId == 0) {
128  $sql = "select nextval(pg_get_serial_sequence('cuadmemailtmpl', 'tmpl_id'))";
129  $sth = db_query($sql, $dbh);
130  if (!$sth) {
131  throw new exception ("nextval query failed.", 16);
132  }
133  $row = db_fetch_row($sth, 0);
134  $templateId = intval($row[0]);
135  $updateTable["tmpl_id"] = $templateId;
136  $updateTable["_action"] = "insert";
137  $shortAction = "ADD_ETEMPL";
138  $longAction = "Add Email Template";
139  } else {
140  $updateTable["_action"] = "update";
141  $shortAction = "UPD_ETEMPL";
142  $updateTable["tmpl_id"] = $templateId;
143  $longAction = "Update Email Template";
144  }
145 
146  $sql = "select email from cuadminusers where user_name = '$Cn' and cu = '$Cu'";
147  $sth = db_query($sql, $dbh);
148  if (!$sth) {
149  throw new exception("Email query failed.", 14);
150  }
151 
152  $email = trim(db_fetch_row($sth, 0)[0]);
153 
154  $updateTable = array("cuadmemailtmpl" => array($updateTable));
155  if (DataAdminTableUpdate($dbh, array("cu" => $Cu), $updateTable, $Cn, $shortAction, "broadcastEmails.prg", "A", $longAction, $Cn, $email,
156  trim($_SERVER["REMOTE_ADDR"])) === false) {
157  throw new exception("Update failed.", 1);
158  }
159 
160  $results = ReadTemplate($dbh, $Cu);
161  if ($results ["status"] !== "000") {
162  throw new exception ("Read Template failed.", 17);
163  }
164  $templateDDL = $results ["data"] ["templateDDL"];
165 
166  $returnArray = array("status" => "000", "error" => "", "data" => array("templateDDL" => $templateDDL, "templateId" => $templateId), "info" => "Template was saved successfully.",
167  "operation" => "saveTemplate");
168  } catch(exception $e) {
169  $returnArray = array("status" => $e->getCode(), "error" => $e->getMessage(), "data" => array("templateDDL" => array(), "templateId" => 0), "operation" => "saveTemplate");
170  }
171  return $returnArray;
172 }
173 
174 /**
175  * function _ValidateTemplate ($testAddress, $fromEmail, $subject, $select, $templateName, $selectArray, $optin)
176  * Ensures that the input is valid.
177  *
178  * @param $testAddress -- the address to send to when previewing.
179  * @param $fromEmail -- the address to show that the email was sent from.
180  * @param $subject -- the subject of the email.
181  * @param $select -- the value of the select dropdownlist. It has to be in a predefined list.
182  * @param $templateName -- the name to save the template as. (For send preview, this is not validated.)
183  * @param $selectArray -- the array to ensure that the select option fits.
184  * @param $optin -- {0 or 1} If one, the user must be opted in to get the email.
185  *
186  * @return "status" -- "000" if successful, nonzero otherwise.
187  * @return "error" -- empty string if successful, nonempty otherwise.
188  */
189 function _ValidateTemplate ($testAddress, $fromEmail, $subject, $select, $templateName, $selectArray, $optin) {
190  try {
191  if ($fromEmail == "") {
192  throw new exception ("From email is required.", 12);
193  }
194 
195  if (!validateEmail($fromEmail)) {
196  throw new exception("From address is not valid.", 7);
197  }
198  if ($subject == "") {
199  throw new exception ("Subject is required.", 3);
200  }
201  if ($templateName == "") {
202  throw new exception ("Name is required.", 15);
203  }
204 
205  if (!isset($selectArray) || !is_array($selectArray)) {
206  throw new exception ("Select array is not valid.", 2);
207  }
208 
209  if (!in_array($select, $selectArray)) {
210  throw new exception ("Select is invalid.", 5);
211  }
212 
213  if ($testAddress != "" && !validateEmail($testAddress)) {
214  throw new exception("Test address is not valid.", 1);
215  }
216 
217  if (!in_array($optin, array("N","Y"))) {
218  throw new exception ("Optin is not valid.", 4);
219  }
220 
221  $returnArray = array("status" => "000", "error" => "");
222  } catch (exception $e) {
223  $returnArray = array("status" => $e->getCode(), "error" => $e->getMessage());
224  }
225  return $returnArray;
226 }
227 
228 /**
229  * function SendEmail($dbh, $Cu, $logger, $encoded)
230  * Sends emails to a predetermined list. Updates the lastused column.
231  *
232  * @param integer $dbh -- the database connection
233  * @param string $Cu -- the credit union
234  * @param class $logger -- used to log which email addresses are sent to
235  * @param string $encoded -- the encoded version of the SQL to run (from preparing the email.)
236  *
237  * @return "status" -- "000" if successful, nonzero otherwise
238  * @return "error" -- empty string if successful, nonempty otherwise
239  * @return "info" -- message to the user when successful
240  * @return "operation" -- the operation to distinguish afterwards
241  */
242 function SendEmail($dbh, $Cu, $logger, $encoded) {
243  $tagList = GetTagList();
244  try {
245  if ($encoded == "") {
246  throw new exception("Encoded is required.", 2);
247  }
248  $encoded = HCU_PayloadDecode($Cu, $encoded);
249 
250  if (!is_array($encoded)) {
251  throw new exception("Encoded is not encoded correctly.", 3);
252  }
253 
254  if (!HCU_array_key_exists("realSQL", $encoded) || !HCU_array_key_exists("body", $encoded) || !HCU_array_key_exists("fromName", $encoded) ||
255  !HCU_array_key_exists("templateId", $encoded) || !HCU_array_key_exists("templateId", $encoded) || !HCU_array_key_exists("subject", $encoded) ||
256  !HCU_array_key_exists("fromEmail", $encoded)) {
257  throw new exception("Encoded is not encoded correctly.", 5);
258  }
259  extract($encoded);
260 
261  $body = strip_tags($body, $tagList); // Remove tags that aren't "approved." This is done on the prepare but do it again just to be sure.
262 
263  if ($templateId != 0) {
264  $sql = "update cuadmemailtmpl set tmpl_lastused = now() where tmpl_id = $templateId and cu = '$Cu'";
265  $sth = db_query($sql, $dbh);
266  if (!$sth) {
267  throw new exception("Update query failed.", 1);
268  }
269  }
270 
271  $sth = db_query($realSQL, $dbh);
272  if (!$sth) {
273  throw new exception("Email read query failed.", 4);
274  }
275 
276  $notify = new ErrorMail;
277  $notify->mailfrom = $fromEmail;
278  $notify->mailfromname = $fromName;
279  $notify->subject = $subject;
280  $notify->htmlMsgbody = $body;
281  $notify->bulk = true;
282  $notify->executeQuietly = true;
283  $notify->callingfunction = __FUNCTION__;
284  $notify->file = __FILE__;
285  $notify->cu = $Cu;
286 
287  $results = db_fetch_all($sth);
288  $results = $results === false ? array() : $results;
289  $emails = array();
290 
291  foreach($results as $result) {
292  $emails[] = $result["email"];
293  }
294 
295  $notify->mailto = $emails;
296  $notify->hideto = true;
297  $notify->SendMail();
298 
299  $returnArray = array("status" => "000", "error" => "", "info" => "Emails were sent successfully.", "operation" => "sendEmail");
300  } catch(exception $e) {
301  $returnArray = array("status" => $e->getCode(), "error" => $e->getMessage(), "operation" => "sendEmail");
302  }
303  return $returnArray;
304 }
305 
306 /**
307  * function ReadSetup($dbh, $Cu)
308  * reads in all the templates for the particular CU
309  *
310  * @param integer $dbh -- the database connection
311  * @param string $Cu -- the credit union
312  *
313  * @return "status" -- "000" if successful, nonzero otherwise
314  * @return "error" -- empty string if successful, nonempty otherwise
315  * @return "data"."templateDDL" -- a list of data for the template dropdownlist
316  * @return "data"."emailList" -- a list of data for the fromEmail dropdownlist
317  * @return "data"."hasUnverified" -- if true, then we need to get the statuses from Amazon
318  * @return "operation" -- the operation to distinguish afterwards
319  */
320 function ReadSetup($dbh, $Cu) {
321  $templateDDL = array();
322  $emailList = array();
323  try {
324  $results = ReadTemplate($dbh, $Cu);
325  if ($results ["status"] !== "000") {
326  throw new exception ("Read Template failed.", 1);
327  }
328  $templateDDL = $results["data"]["templateDDL"];
329 
330  $sql = "select lower(trim(r.email)) as email, r.verified from json_to_recordset((select a.email from cuadmnotify a where a.role = 'SES' and a.cu = '" .
331  prep_save($Cu, 10) . "')::json) as r (email varchar, verified boolean) order by 1";
332  $sth = db_query($sql, $dbh);
333  if (!$sth) {
334  throw new exception ("Verified query failed.", 2);
335  }
336  $emailList = db_fetch_all($sth);
337  $emailList = $emailList === false ? array() : $emailList;
338 
339  $hasUnverified = false;
340 
341  $verifiedList = array();
342  foreach($emailList as $emailRow) {
343  if ($emailRow["verified"] === "t") {
344  $verifiedList[] = array("email" => $emailRow["email"]);
345  } else if (!$hasUnverified) {
346  $hasUnverified = true;
347  }
348  }
349 
350  $returnArray = array("status" => "000", "error" => "", "data" => array("templateDDL" => $templateDDL, "emailList" => $verifiedList, "hasUnverified" =>
351  $hasUnverified), "operation" => "readSetup");
352  } catch(exception $e) {
353  $returnArray = array("status" => $e->getCode(), "error" => $e->getMessage(), "data" => array("templateDDL" => array(), "emailList" => array(),
354  "hasUnverified" => false), "operation" => "readSetup");
355  }
356  return $returnArray;
357 }
358 
359 /**
360  * function ReadTemplate($dbh, $Cu)
361  * Reads the templates from the template table.
362  *
363  * @param integer $dbh -- the database connection
364  * @param string $Cu -- the credit union
365  *
366  * @return "status" -- "000" if successful, nonzero otherwise
367  * @return "error" -- empty string if successful, nonempty otherwise
368  * @return "data"."templateDDL" -- a list of data for the template dropdownlist
369  * @return "operation" -- the operation to distinguish afterwards
370  */
371 function ReadTemplate($dbh, $Cu) {
372  try {
373  $selectArray = GetSelectArray();
374  $sql = "select tmpl_id as value, tmpl_name as text, lower(trim(tmpl_email)) as fromemail, tmpl_email_name as fromname, tmpl_subject as subject,
375  tmpl_message as body,
376  case when tmpl_opt_mailto = 1 then 'Y' else 'N' end as optin, tmpl_opt_mbr as select from cuadmemailtmpl where cu = '$Cu' order by tmpl_name";
377 
378  $sth = db_query($sql, $dbh);
379  if (!$sth) {
380  throw new exception("Select query failed.", 1);
381  }
382  $templateDDL = db_fetch_all($sth);
383  $templateDDL = $templateDDL === false ? array() : $templateDDL;
384 
385  foreach($templateDDL as $i => $row) {
386  $templateDDL[$i]["select"] = HCU_array_key_value($row["select"], $selectArray);
387  }
388 
389  $returnArray = array("status" => "000", "error" => "", "data" => array("templateDDL" => $templateDDL));
390  } catch (exception $e) {
391  $returnArray = array("status" => $e->getCode(), "error" => $e->getMessage(), "data" => array("templateDDL" => array()));
392  }
393  return $returnArray;
394 }
395 
396 /**
397  * function PrepareEmail($dbh, $Cu, $testAddress, $body, $fromEmail, $fromName, $subject, $optin, $select, $templateId)
398  * Prepares the email for sending. It creates the full with the email contents and list. If there is a test email, then it sends to that email.
399  *
400  * @param integer $dbh -- the database connection
401  * @param string $Cu -- the credit union
402  * @param string $testAddress -- the test address to send preview to
403  * @param string $body -- the body of the email
404  * @param string $fromEmail -- the email to send email from
405  * @param string $fromName -- the name of the from email
406  * @param string $subject -- the subject of the email
407  * @param string $optin -- does the user have to opt in to see the email?
408  * @param string $select -- the value of the select option (all members, members with E-statements, etc.)
409  * @param number $templateId -- the id of the template. If it is zero, then create a template.
410  *
411  * @return "status" -- "000" if successful, nonzero otherwise
412  * @return "error" -- empty string if successful, nonempty otherwise
413  * @return "data"."numEmails" -- returns the value from the count version of the query
414  * @return "data"."testSent" -- returns a true/false value on if the test email was sent
415  * @return "data"."encoded" -- returns a encoded version of the read SQL. This will be extracted and sent later.
416  * @return "operation" -- the operation to distinguish afterwards
417  *
418  * @todo What do I do about the plain email option?
419  */
420 function PrepareEmail($dbh, $Cu, $testAddress, $body, $fromEmail, $fromName, $subject, $optin, $select, $templateId) {
421  $numEmails = 0;
422  $testSent = false;
423  $selectArray = GetSelectArray();
424  $tagList = GetTagList();
425 
426  try {
427  $results = _ValidateTemplate ($testAddress, $fromEmail, $subject, $select, "unused", $selectArray, $optin);
428  if ($results ["status"] !== "000") {
429  throw new exception ($results ["error"], 10);
430  }
431 
432  $fromEmail = strtolower(trim($fromEmail));
433 
434  $emailFlag = GetMsgTxValue('MSGTX_FORCE_EM');
435  $askBillPay = GetUserFlagsValue('MEM_ASKBPAY');
436  $results = _ConstructSQL($Cu, $optin, $select, $emailFlag, $askBillPay);
437  if ($results ["status"] !== "000") {
438  throw new exception ("SQL failed.", 9);
439  }
440  extract($results["data"]);
441 
442  $countSQL = "select count(distinct lower(trim(u.email))) $baseSQL";
443  $realSQL = "select distinct lower(trim(u.email)) as email $baseSQL";
444 
445  $body = strip_tags($body, $tagList); // Remove tags that aren't "approved"
446 
447  $sth = db_query($countSQL, $dbh);
448  if (!$sth) {
449  throw new exception("Query failed.", 6);
450  }
451  $numEmails = intval(db_fetch_row($sth, 0)[0]);
452 
453  if ($testAddress != "") {
454  // Send email
455  $notify = new ErrorMail;
456  $notify->mailto = $testAddress;
457  $notify->mailfrom = $fromEmail;
458  $notify->mailfromname = $fromName;
459  $notify->subject = $subject;
460  $notify->htmlMsgbody = $body;
461  $notify->cu = $Cu;
462  $notify->file = __FILE__;
463  $notify->callingfunction = __FUNCTION__;
464  $notify->SendMail();
465 
466  $testSent = true;
467  }
468 
469  $encoded = HCU_PayloadEncode($Cu, array("realSQL" => $realSQL, "body" => $body, "fromEmail" => $fromEmail, "templateId" => $templateId,
470  "subject" => $subject, "fromName" => $fromName));
471 
472  $returnArray = array("status" => "000", "error" => "", "data" => array("numEmails" => $numEmails, "testSent" => $testSent, "encoded" => $encoded),
473  "operation" => "prepareEmail");
474  } catch(exception $e) {
475  $returnArray = array("status" => $e->getCode(), "error" => array($e->getMessage()), "data" => array("numEmails" => 0, "testSent" => false, "encoded" => ""),
476  "operation" => "prepareEmail");
477  }
478  return $returnArray;
479 }
480 
481 /**
482  * function _ConstructSQL($Cu, $optin, $select, $emailFlag, $askBillPay)
483  * Creates the SQL according to the parameters.
484  *
485  * @param $Cu -- the credit union
486  * @param $optin -- {0,1} should a user have to opted in to receive the email?
487  * @param $select -- the value of the select option (all members, members with E-statements, etc.)
488  * @param $emailFlag -- the value of the email flag. (Defined in cu_flagconst.i)
489  * @param $askBillPay -- the value of the bill pay flag. (Defined in cu_flagconst.i)
490  *
491  * @return "status" -- "000" if successful, nonzero otherwise
492  * @return "error" -- empty string if successful, nonempty otherwise
493  * @return "data"."baseSQL" -- the results of the SQL
494  */
495 function _ConstructSQL($Cu, $optin, $select, $emailFlag, $askBillPay) {
496  try {
497  $sql = "from ${Cu}user u ";
498  $where = array("coalesce(trim(u.email), '') <> ''", "(coalesce(u.msg_tx, 0) & $emailFlag) = 0"); // has email and is not flagged as a bad email.
499 
500  switch($select) {
501  case "withE":
502  $sql .= " inner join (select user_id, accountnumber, row_number() over (partition by user_id, accountnumber) as rown
503  from ${Cu}useraccounts) uc on u.user_id = uc.user_id and uc.rown = 1";
504  $where[] = "exists (select 'FOUND' from ${Cu}memberacct ma where uc.accountnumber = ma.accountnumber and estmnt_flag = 'Y')";
505  break;
506  case "withoutE":
507  $sql .= " inner join (select user_id, accountnumber, row_number() over (partition by user_id, accountnumber) as rown
508  from ${Cu}useraccounts) uc on u.user_id = uc.user_id and uc.rown = 1";
509  $where[] = "not exists (select 'FOUND' from ${Cu}memberacct ma where uc.accountnumber = ma.accountnumber and estmnt_flag = 'Y')";
510  break;
511  // #3044: BillPay flag is only used here
512  // If necessary, we will need to use perms on profile
513  // --------------------
514  // case "withBP":
515  // $where[] = "(u.userflags & $askBillPay) <> 0";
516  // break;
517  case "withText":
518  $sql .= " inner join (select user_id, accountnumber, row_number() over (partition by user_id, accountnumber) as rown
519  from ${Cu}useraccounts) uc on u.user_id = uc.user_id and uc.rown = 1";
520  $where[] = "exists (select 'FOUND' from cusms s where u.user_id = s.user_id and uc.accountnumber = s.accountnumber
521  and coalesce(trim(s.cellnumber::text), '') <> '' and s.cu = '${Cu}')";
522  break;
523  case "all":
524  break;
525  default:
526  throw new exception("Option is not valid.", 6);
527  }
528 
529  if ($optin == 1) {
530  $where[] = "u.egenl_flag = 'Y'";
531  }
532 
533  if (count($where) > 0) {
534  $sql .= " where " . implode(" and ", $where);
535  }
536 
537  $returnArray = array("status" => "000", "error" => "", "data" => array("baseSQL" => $sql));
538  } catch (exception $e) {
539  $returnArray = array("status" => $e->getCode(), "error" => $e->getMessage(), "data" => array("baseSQL" => ""));
540  }
541  return $returnArray;
542 }
543 
544 /**
545  * function UpdateEmailList($dbh, $Cu)
546  * Iff there are unverified emails in the CU's SES role, then do a separate call to potientally update list from Amazon.
547  *
548  * @param $dbh -- the database connection
549  * @param $Cu -- the credit union
550  *
551  * @return "status" -- "000" if successful, nonzero otherwise
552  * @return "error" -- empty string if successful, nonempty otherwise
553  * @return "data"."emailList" -- a list of verified emails after calling Amazon
554  * @return "operation" -- the operation to distinguish afterwards
555  */
556 function UpdateEmailList($dbh, $Cu) {
557  try {
558  $results = ReadVerifiedEmailList($dbh, $Cu);
559  if ($results ["status"] !== "000") {
560  throw new exception ("ReadVerifiedEmailList failed.", 1);
561  }
562 
563  $emailList = array();
564  foreach($results ["verifiedEmailList"] as $emailRow) {
565  if ($emailRow["status"] === "Success") {
566  $emailList[] = array("email" => strtolower(trim($emailRow["email"])));
567  }
568  }
569 
570  $returnArray = array("status" => "000", "error" => "", "data" => array("emailList" => $emailList), "operation" => "updateEmailList");
571  } catch (exception $e) {
572  $returnArray = array("status" => $e->getCode(), "error" => $e->getMessage(), "data" => array("emailList" => array()), "operation" => "updateEmailList");
573  }
574  return $returnArray;
575 }