Send email for all UserLevel 2

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.

Send email for all UserLevel 2

Postby eayvl » Thu Jan 11, 2018 8:56 am

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;
}
eayvl
 
Posts: 108
Joined: Thu Feb 05, 2015 2:50 am

Re: Send email for all UserLevel 2

Postby arbei » Thu Jan 11, 2018 1:02 pm

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>;
arbei
 
Posts: 1499
Joined: Wed Sep 09, 2015 10:13 am

Re: Send email for all UserLevel 2

Postby eayvl » Fri Jan 12, 2018 3:29 am

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";
eayvl
 
Posts: 108
Joined: Thu Feb 05, 2015 2:50 am

Re: Send email for all UserLevel 2

Postby arbei » Fri Jan 12, 2018 10:02 am

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;
arbei
 
Posts: 1499
Joined: Wed Sep 09, 2015 10:13 am

Re: Send email for all UserLevel 2

Postby eayvl » Sat Jan 13, 2018 5:41 am

arbei resolved! thank you very much.
eayvl
 
Posts: 108
Joined: Thu Feb 05, 2015 2:50 am


Return to General Discussion (PHPMaker)