biggieuk Posted May 28, 2008 Share Posted May 28, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/107606-solved-loops-within-mail-body/ Share on other sites More sharing options...
MadTechie Posted May 28, 2008 Share Posted May 28, 2008 whats the problem ? Quote Link to comment https://forums.phpfreaks.com/topic/107606-solved-loops-within-mail-body/#findComment-551529 Share on other sites More sharing options...
biggieuk Posted May 28, 2008 Author Share Posted May 28, 2008 sorry, im receiving a parse error on line 50, which is: foreach($_SESSION['am'] as $key=>$value) im guessing ive not put the foreach loop into the $msg variable correctly? Quote Link to comment https://forums.phpfreaks.com/topic/107606-solved-loops-within-mail-body/#findComment-551533 Share on other sites More sharing options...
MadTechie Posted May 28, 2008 Share Posted May 28, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/107606-solved-loops-within-mail-body/#findComment-551538 Share on other sites More sharing options...
biggieuk Posted May 28, 2008 Author Share Posted May 28, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/107606-solved-loops-within-mail-body/#findComment-551801 Share on other sites More sharing options...
MadTechie Posted May 28, 2008 Share Posted May 28, 2008 opps okay change the <br /> to /n ie $msg.= $value. '<br />'; to $msg.= $value. '/n'; Quote Link to comment https://forums.phpfreaks.com/topic/107606-solved-loops-within-mail-body/#findComment-552014 Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/107606-solved-loops-within-mail-body/#findComment-552021 Share on other sites More sharing options...
biggieuk Posted May 28, 2008 Author Share Posted May 28, 2008 thanks very much, both variations work great! Quote Link to comment https://forums.phpfreaks.com/topic/107606-solved-loops-within-mail-body/#findComment-552185 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.