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
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);
?>

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.