Forum Moderators: coopster

Message Too Old, No Replies

Using Mail() feature with a do while statement

I need to call a do_while statement in my mail $body variable

         

Honestpianist

9:13 am on Aug 12, 2008 (gmt 0)

10+ Year Member



I currently have a php mail() script running properly with a variable calling content for the body. I need to implement the content from a do_while into the body of my email as well.

***********CODE I NEED TO IMPLEMENT:

$i = 1;

do
{
echo"Firm:"; if(isset($_SESSION['5b_firm_'.$i])){echo $_SESSION['5b_firm_'.$i];}
$i++;
}
while ($i <= $_SESSION['amount_of_additional_counsels']);

***********MY MAIL() CODE:

$body = "Date Ordered: $ordered";
mail ("orders@example.com", "Order - Example", $body, "From: " . $from . "\n");

Please help me. Thank you.

whoisgregg

1:28 pm on Aug 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of echo'ing that additional content, you can concatenate it into a variable [php.net]. Then, echo the variable and concatenate it into the mail() body variable. Untested code:

$i = 1;
$firm_html = '';
do
{
$firm_html .= "Firm:"; if(isset($_SESSION['5b_firm_'.$i])){$firm_html .= $_SESSION['5b_firm_'.$i];}
$i++;
}
while ($i <= $_SESSION['amount_of_additional_counsels']);
echo $firm_html; // this outputs it with the rest of the HTML
$body = "Date Ordered: $ordered";
mail ("orders@example.com", "Order - Example", $body . $firm_html, "From: " . $from . "\n"); // adding it here also outputs it with the email

Honestpianist

9:41 am on Aug 13, 2008 (gmt 0)

10+ Year Member



I ended up doing something like that and it works. Thank you.

whoisgregg

1:49 pm on Aug 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted. :)

And, before I completely forget my manners, welcome to WebmasterWorld!