Page 1 of 1

trying to include an array into the body of an email

Posted: Thu Mar 20, 2003 6:16 pm
by jesso3
Hi. I am trying to email the contents generated by an array. The results get displayed on the screen, but when I try to email those results, only part of it get sent. Any ideas what I am doing wrong? Code is below. One problem in the past is not identing my code properly. I hope I done it right to encourage response. Thanks.

$to = array($email); //email address taken from a form
$sizeof5 = count($to); //use array in case I use multiple addresses
$subject = "Test Results";

for($i=0;$i<count($sizeof);$i++) //$sizeof is an array defined in PHP
{

for($i=0;$i<count($sizeof2);$i++) //$sizeof2 is an array defined in PHP
{
$output = $sizeof[$i];
$output2 = $sizeof2[$i];
$output3 = $answers[$i]; // $answers is an array taken from cookie
$realy=$i+1; //$realy is question number being incremented each time a line is printed
// comparing value of one array to another

if ($output3==$output)
{
// give results to be printed a value
$ans = "$speechst Question $realy - Correct.";
echo "$speechst Question $realy - Correct."; //print results on screen
$me .= $ans; //add this value as an array to anothe variable
// add this variable to the body of the message. This block of code is similar to the else statement below
$body = "$email, $name, $Company, $City,
$phone_no,$currentgrade, $currentScore, $me"; // problem is that $me do not contain what is supposed to get sent based on the body of the email when it is sent. Any ideas?? :idea:
}

else
{
$ans = "$speechst Question $realy - Incorrect. Actual Answer was :$output2";
echo "$speechst Question $realy - Incorrect. Actual Answer was :$output2";
$me .= $ans[$i];
$body = "$email, $name, $Company, $City, $phone_no, $currentgrade, $currentScore, $me";
}
}
}

$hdr = "From: somewhere\r\n";

$hdr .= "Return-Path: $me@somewhere.com\r\n";

if($cc){$hdr .= "Cc: $cc\r\n";}

if($bcc){$hdr .= "Bcc: $bcc\r\n";}

for($x = 0; $x < $sizeof5; $x++){

if(mail($to[$x], $subject, $body, $hdr))

{

$status = "Your message was successfully sent.";

}

else

{

$status = "An error occurred while sending your message.";

}

}[/b]

Posted: Fri Mar 21, 2003 6:39 am
by rodrigocaldeira
You are using $i 2 times in your for statement.

Try to use a $i variable in the external for, and a $j variable in the internal for.