Jump to content

[SOLVED] loops within mail() body


biggieuk

Recommended Posts

Hi all,

 

I am trying to send an e-mail with the following message body:

 

<POSTed value>

 

------------------------------

Details:

 

Name:

email:

 

Morning Sessions:

 

<array[0]> = value

<array[1]> = value

 

......

 

 

 

 

the code i am using is:

 

$to = $email;
$subj = "PESDC Booking Confirmation";
$msg = $_POST['dbemail'];
$msg.= "\n
---------------------------------------------
Name: $name
E-mail: $email

Morning:
".
foreach($_SESSION['am'] as $key=>$value)
    {
    echo $value. '<br />';
    }
."
Afternoon:
".
foreach($_SESSION['pm'] as $key=>$value2)
    {
     echo $value2. '<br />';
    }


$header = "From: confirmation";

$mailsend = mail($to, $subj, $msg, $header);

 

SESSION['am'] and SESSION['pm'] are separate arrays stored in a session variable.

 

What is the correct method of doing this?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/107606-solved-loops-within-mail-body/
Share on other sites

ahh i see

 

you can not concat a function..

 

try this

<?php
$to = $email;
$subj = "PESDC Booking Confirmation";
$msg = $_POST['dbemail'];
$msg.= "\n
---------------------------------------------
Name: $name
E-mail: $email

Morning:
";
foreach($_SESSION['am'] as $key=>$value)
    {
    $msg.= $value. '<br />';
    }
$msg.="Afternoon:<br>";

foreach($_SESSION['pm'] as $key=>$value2)
    {
     $msg.= $value2. '<br />';
    }


$header = "From: confirmation";

$mailsend = mail($to, $subj, $msg, $header);
?>

thanks for this, seems to be working apart from the formatting.

 

Im receiving:

 

Morning:
Sport<br />Maths<br />Afternoon:<br>Radiology<br />Physiotherapy<br />

 

wheres it should be more like:

 

Morning:
Sport
Maths

Afternoon:
Radiology
Physiotherapy

 

How could i change the code to reflect this?

 

thanks again!

implode seems to be the better option here...

 

<?php
$to = $email;
$subj = "PESDC Booking Confirmation";
$msg = $_POST['dbemail'];
$msg.= "\n
---------------------------------------------
Name: $name
E-mail: $email

Morning:
".implode("\n",$_SESSION['am'])."
Afternoon:
".implode("\n",$_SESSION['pm']);

$header = "From: confirmation";

$mailsend = mail($to, $subj, $msg, $header);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.