Viz
Viz

Reputation: 15

PHPmailer, foreach loop in body

I'm using the PHPMailer script for my site. However, can't figure out how to use a foreach loop to send to the recipient. Tried a bunch of different things.

Basically the code.

$mail->Body    = "message" . foreach ($_SESSION as $key => $value) { }. 
"another message";

If I do that, it just errors out. What would the solution be? Thanks in advance.

Upvotes: 0

Views: 1379

Answers (1)

Amazone
Amazone

Reputation: 436

I don't know what you want send by mail, but if you want send all the session array, it's like this:

$mail->Body    = "message";//start of body
foreach ($_SESSION as $key => $value) { 
  $mail->Body .= $key.'  '.$value.'<br>';//each line of session
}

$mail->Body .= "another message";//end of body

Upvotes: 1

Related Questions