I am trying to email a student list. Student list data saved already in a database.
So I created a query to retrieve the data according to the merchTxnRef
then retriveing the row from the table/record and assign it to a variable..
and then concatenate the variable to the mail body and trying to send them.
but my <tr></tr>
is empty in the mail.. I know it is because of I am saving the foreach loop variable incorrectly to this variable $studentList
how can I save the foreach loop values in a variable and print it outside of the loop
Following is the code I am trying.
$sqlListst = "SELECT * FROM tck_paymentStudents WHERE merchTxnRef LIKE $merchTxnRef'";
$resultListst = $wpdb->get_results($sql) or die(mysql_error());
foreach( $resultListst as $resultsListst ) {
$merchTxnRef = $resultsListst->merchTxnRef;
$sudentname = $resultsListst->sudentname;
$admissionnmbr = $resultsListst->admissionnmbr;
$purpose = $resultsListst->purpose;
$amount = $resultsListst->amount;
$grade = $resultsListst->grade;
$studentList = '<tr><td>'.$merchTxnRef.'</td><td>'.$sudentname.'</td><td>'.$admissionnmbr.'</td><td>'.$purpose.'</td><td>'.$amount.'</td><td>'.$grade.'</td></tr>';
}
$mail_body_guest_full = '<table>';
$mail_body_guest_full .= $studentList;
$mail_body_guest_full .= '</table>';
$email = 'myemail@examplsite.com';
$subject = 'Student List';
$from_guest = 'guestemail@gmail.com';
$headers_guest = array('From: My Site <'.$from_guest.'>');
$mail_sent_guest = wp_mail( $email, $subject, $mail_body_guest_full, $headers_guest );