Page 1 of 1
Send email for all UserLevel 2
Posted: Thu Jan 11, 2018 8:56 am
by eayvl
Hi, i want to send the mail to all UserLevel = 2 but only mail arrives to a single employee, thank you very much for your help.
// Email Sending event
function Email_Sending(&$Email, &$Args) {
$Email->Recipient = ew_ExecuteScalar("SELECT Email FROM EMPLOYEES WHERE UserLevel = '2'");
$Email->Subject = "Solicitud de Financiamiento AP";
$Email->Format = "HTML";
$Email->Charset = "UTF-8";
$Email->Content = "<html><style>body {font-family: Arial, Helvetica, sans-serif; font-size: 16px;color: #000;}</p><h3>Financiamiento AP / Agregado por</h3><p></style><body>'". CurrentUserName();
//busca el nombre del cliente en la base de datos nysn
$uln = ew_ExecuteScalar("SELECT nysn_cliente FROM nysn WHERE nysn_id = '" . $Args["rsnew"]["ap_2_cliente"] ."'");
$Email->Content .= "<BR><BR><BR><table border='1' bgcolor='#ffe6cc'>
<tbody>
<tr>
<td><b>Cliente :</b></td>
<td>:</td>
<td>" . $uln . "</td>
</tr>
<tr>
<td><b>Concepto :</b></td>
<td>:</td>
<td>" . $Args["rsnew"]["ap_2_concepto_1"] . "</td>
</tr>
<tr>
<td><b>Monto Financiado :</b></td>
<td>:</td>
<td>" . $Args["rsnew"]["ap_2_monto"] . "</td>
</tr>
<tr>
<td><b>Fecha Compromiso de Pago :</b></td>
<td>:</td>
<td>" . $Args["rsnew"]["ap_2_fecha_compromiso"] . "</td>
</tr>
</tbody>
</table>";
return TRUE;
}
Re: Send email for all UserLevel 2
Posted: Thu Jan 11, 2018 1:02 pm
by arbei
ew_ExecuteScalar() will only return the first value of first row of the records.
You need to use Conn->Execute() to retrieve all row and concatenate the email address to the recipient.
For example:
$rs = ew_ExecuteScalar("SELECT Email FROM EMPLOYEES WHERE UserLevel = '2'");
//
// loop the $rs and concatenate the email addrress.
//
$Email->Recipient = <List of email address>;
Re: Send email for all UserLevel 2
Posted: Fri Jan 12, 2018 3:29 am
by eayvl
Thanks for your quick response arbei, change the code, but I still get this message "You must provide at least one recipient email address."
$rs = ew_ExecuteScalar("SELECT Email FROM EMPLOYEES WHERE UserLevel = '2'");
$Email->Recipient = $GLOBALS["conn"]->Execute($rs);
$Email->Subject = "Solicitud de Financiamiento AP";
$Email->Format = "HTML";
$Email->Charset = "UTF-8";
Re: Send email for all UserLevel 2
Posted: Fri Jan 12, 2018 10:02 am
by arbei
eayvl wrote:
$rs = ew_ExecuteScalar("SELECT Email FROM EMPLOYEES WHERE UserLevel =
'2'");
$Email->Recipient = $GLOBALS["conn"]->Execute($rs);
The above code is not correct. You should loop through the $rs (which is recordset) and make it as string.
For example:
While(!$rs->EOF){
if ($recipients <> "")
$recipeients .= ","
$recipients .= $rs("<EMAIL>");
}
$Email->Recipient = $recipients;
Re: Send email for all UserLevel 2
Posted: Sat Jan 13, 2018 5:41 am
by eayvl
arbei resolved! thank you very much.