简体   繁体   中英

Codeigniter Foreach within an Email Message

When using the foreach within the message:

$this->email->message('The following orders have backorders:<br><br>'.foreach ($backOrdersArray as $row2)
{
echo $OrderNumber.
'<br>Kind Regaards,<br>Merchant Lite');
};

Error:

PHP Parse error:  syntax error, unexpected 'foreach' (T_FOREACH)

The code provided originally sends the email but only with one order number (and not multiple)

_

Update with print of backorders array as requested:

array(1) { [0]=> object(stdClass)#27 (1) { ["ORDER"]=> string(9) "SPA1" } } 

array(6) { [0]=> object(stdClass)#64 (1) { ["ORDER"]=> string(11) "BHS2" } [1]=> object(stdClass)#65 (1) { ["ORDER"]=> string(11) "BHS3" } [2]=> object(stdClass)#66 (1) { ["ORDER"]=> string(11) "BHS4" } [3]=> object(stdClass)#67 (1) { ["ORDER"]=> string(11) "BHS5" } [4]=> object(stdClass)#68 (1) { ["ORDER"]=> string(11) "BHS6" } [5]=> object(stdClass)#69 (1) { ["ORDER"]=> string(11) "BHS7" } } 

array(2) { [0]=> object(stdClass)#71 (1) { ["ORDER"]=> string(9) "10G1" } [1]=> object(stdClass)#72 (1) { ["ORDER"]=> string(9) "10G2" } } 

These are generated within a foreach (To get the back orders for each customer)

-

I'm getting some problems trying to get this working. Is there anyway to get a foreach to loop through a list of numbers and print them in the message?

For example, I have a list of order numbers from a database query . I want to show these in the message of the email. I have tried to put the foreach within the message, but that results in an error message.

This is my current code. I have also tried the foreach within the message with no success:

$this->load->library('email');
$this->email->from($CustomersEmail);
$this->email->to($NoReply);

$this->email->subject('Back Orders');

foreach ($backOrdersArray as $row2)
{
    $OrderNumber = $row2->ORDER;
    echo $OrderNumber;
    echo '<br>';
    $this->email->message('The following orders have backorders:<br><br>'.$OrderNumber.'.);
};

$this->email->send();

Any help would be great.

Try this

$this->load->library('email');
$this->email->from($CustomersEmail);
$this->email->to($NoReply);
$this->email->subject('Back Orders');


$msg = "The following orders have backorders:<br><br>";
foreach ($backOrdersArray as $row2)
{
    $OrderNumber = $row2->ORDER;
    $msg .='<br>';
    $msg .=  $OrderNumber;
};

$this->email->message($msg);
$this->email->send();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM