This code for the body of email that i want to send...so i want to loop for the name so i will display like this name abu,name ali,name rajesh
$z = oci_parse($conn, "SELECT name FROM usr where usr_id=:num1");
oci_bind_by_name($z, ":num1",$INIT);
oci_execute($z);
$row = oci_fetch_row($z);
$MERC_HAND_USR_ID_name[]=$row[0];
}
$body='Dear Helpdesk Manager
We would like to inform that a new report has been made by.
Name: '.foreach($MERC_HAND_USR_ID_name as $key => $value)
{
$value;
}.'
date: '. $date.'
time: '. $time.'
Thank You,
- Helpdesk ';
it is possible for me to do like this or there is other way?
Please try this.
$body='Dear Helpdesk Manager
We would like to inform that a new report has been made by.';
foreach($MERC_HAND_USR_ID_name as $key => $value)
{
$body.= '<br>   Name: '.$value;
}
$body.='
<br><br>
date: '.date("Y/m/d").'
<br>
time: '. date("h:i:sa").'
<br><br>Thank You,<br><br>- Helpdesk ';
You must change your $body variable like below
$body='Dear Helpdesk Manager
We would like to inform that a new report has been made by.
';
foreach($MERC_HAND_USR_ID_name as $key => $value)
{
$body .= 'Name: ' . $value . ' ';
}
$body .= '
date: '. $date.'
time: '. $time.'
Thank You,
- Helpdesk ';
Since you have to loop through $MERC_HAND_USR_ID_name, you must prepare the mail body by appending it in your foreach loop.
You cannot use a loop inside a string. You need to create a string with your names first and then concatenate it with the $body string.
Something like this:
$z = oci_parse($conn, "SELECT name FROM usr where usr_id=:num1");
oci_bind_by_name($z, ":num1",$INIT);
oci_execute($z);
$row = oci_fetch_row($z);
$MERC_HAND_USR_ID_name[]=$row[0];
//} // ==> This closes nothing
$names = '';
foreach($MERC_HAND_USR_ID_name as $key => $value) {
$name .= 'Name: ' . $value; //here you can manipulate it however you want... like maybe add a space between values (. ' ') or a line break (<br/>)
}
$body='Dear Helpdesk Manager
We would like to inform that a new report has been made by '.
$name .
'date: '. $date .
'time: '. $time.
'Thank You,
- Helpdesk ';