Send email for all UserLevel 2

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
eayvl
User
Posts: 315

Send email for all UserLevel 2

Post 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;

}


arbei
User
Posts: 9286

Post 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>;


eayvl
User
Posts: 315

Post 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";

arbei
User
Posts: 9286

Post 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;


eayvl
User
Posts: 315

Post by eayvl »

arbei resolved! thank you very much.


Post Reply