Hey everyone, a friend made this site for me a bit ago and I didnt use it until now. He is out of the country and hasnt been on AIM in a while so I cannot get a hold of him. My problem is... In the script below, you will see that there are two emails being sent, one to ($email_id, which is loading correctly from the database) and the other to an email address (t@gmail.com). However, the first email is not getting sent, only the second admin email (to t@gmail.com). Please help! Thank you!







//retrieving sections



$query = "select section_id from section where test_id=$test_id";



$res = mysql_query($query, $con);



while ($row = mysql_fetch_assoc($res))



{



	$section_id = $row['section_id'];



	//retrieving answers



	$query = "select answer_id, category_id, answer_type from answer where section_id=$section_id";



	$res1 = mysql_query($query, $con);







	while ($subrow = mysql_fetch_assoc($res1))



	{



		$answer_id = $subrow['answer_id'];



		$category_id = $subrow['category_id'];



		$answer_type = $subrow['answer_type'];







		$result = mark_answer($answer_id, $user_id);







		switch ($result)



		{



			case 'right':



				$category_marks[$category_id]["num_right"]++;



				$category_scores[$category_id] += 1;



				break;



			case 'wrong':



				$category_marks[$category_id]["num_wrong"]++;



				if ($answer_type=="MC") $category_scores[$category_id] -= 0.25;



				break;



			case 'blank':



				$category_marks[$category_id]["num_blank"]++;



				break;



			case 'error': default:



				$_SESSION['msg'] = "<font color='red'>Mark Answer Error</font>";



				session_commit();



				header("location:./home?test_id=$test_id");



		}


	}


}


//inserting right, wrong, blank value



foreach ($category_marks as $category_id=>$item)



{



	$num_right = $item['num_right'];



	$num_wrong = $item['num_wrong'];



	$num_blank = $item['num_blank'];



	$num_total = $num_right + $num_wrong + $num_blank;



	$query = "insert into category_scores (commit_id, category_id, num_right, num_wrong, num_blank, num_total) 



			values($commit_id, $category_id, $num_right, $num_wrong, $num_blank, $num_total)";



	if (!mysql_query($query, $con))



	{



		$_SESSION['msg'] = "<font color='red'>Category Score Insert Error</font>";



		session_commit();



		header("location:./home?test_id=$test_id");



	}



}



//calcuating type scores for committed test and inserting it into db





//initializing type_score array



$query = "select type_id, code_name from type";



$res = mysql_query($query, $con);







$type_scores = array();



while ($row = mysql_fetch_assoc($res))



{



	$type_id = $row['type_id'];



	$type_scores[$type_id]['type_score'] = 0;



	$type_scores[$type_id]['type_name'] = $row['code_name'];



}



//calculating raw scores



foreach($category_scores as $category_id=>$category_score)



{



	$query = "select type_id from category where category_id=$category_id";



	$res = mysql_query($query, $con);



	$row = mysql_fetch_assoc($res);



	$type_scores[$row['type_id']]['type_score'] += $category_score;



}







//calculating release scores and inserting into db



foreach ($type_scores as $type_id=>&$type)



{



	$score = round($type['type_score']);



	$query = "select release_score 



			from score_convert left join score_convert_content on score_convert.convert_id=score_convert_content.convert_id 



			where test_id=$test_id and type_id=$type_id and raw_score=$score";







	$res = mysql_query($query, $con);







	if (mysql_num_rows($res))



	{



		$row = mysql_fetch_assoc($res);



		$release_score = $row['release_score'];



		if (!$release_score) $release_score = 0;



	}



	else



	{



		$release_score = 0;



	}







	$type['type_score'] = $release_score;







	$query = "insert into type_scores (commit_id, type_id, score) 



			values($commit_id, $type_id, $release_score)";



	if (!mysql_query($query, $con))



	{



		$_SESSION['msg'] = "<font color='red'>Type Score Insert Error</font>";



		session_commit();



		header("location:./home?test_id=$test_id");



	}



}


//Producing PDF Report and reading from disk



$filename = create_pdf_report($user_id, $test_id, $commit_id);


$content_type = "application/pdf";


if(isset($filename)){
	# read a PDF documnet from the disk

	@$fd = fopen($filename, "r");

	@$data = fread($fd, filesize($filename));

	@fclose($fd);
}





//sending email



require_once("_includes/MailAttach.php");



//retrieving email_id and name



$query = "select email_id, concat(first_name, ' ', last_name) as user_name from user where user_id=$user_id";



$res = mysql_query($query, $con);



$row = mysql_fetch_assoc($res);



$email_id = $row['email_id'];



$user_name = $row['user_name'];







//retrieving test name



$query = "select code_name from test where test_id=$test_id";



$res = mysql_query($query, $con);



$row = mysql_fetch_assoc($res);



$test_name = $row['code_name'];







//retrieting committed date



$query = "select date_format(committed_date,'%W, %M, %d, %Y') as committed_date 



		from committed_test where commit_id=$commit_id";



$res = mysql_query($query, $con);



$row = mysql_fetch_assoc($res);



$committed_date = $row['committed_date'];





//To User




$body = "<html><head><title>LE Test Results</title></head>



		<body><p><strong>LE Test Results Posted!</strong></p>



		<p>The following are your Learning Edge test results:</p>



		<p><table width='70%'style='margin-left:30px'>



		<tr><td width='30%'>Student Name:</td><td>$user_name</td></tr>



		<tr><td>Test Taken:</td><td>$test_name</td></tr>



		<tr><td>Date:</td><td>$committed_date</td></tr>



		<tr><td>Scores</td><td></td></tr>



		<tr><td colspan='2'><table width='80%' style='margin-left:50px'>";







foreach ($type_scores as $key=>$val)



{



	extract($val);



	$body .= "<tr><td width='30%'>$type_name</td><td>$type_score</td></tr>";



}







$body .= "</table></p><p>Best Regards,<br />



		<a href='http://www.thelearningedge.net/'>The Learning Edge</a>



		</p></body><html>";





# create object instance
$mail = new MailAttach;



# set all data slots

$mail->from = "noreply@thelearningedge.net";



$mail->to = $email_id;



$mail->subject = "Your Learning Edge Test Results";




//Attach PDF document
//if($filename <> "")
//{
//	# append the attachment
//	$mail->add_attachment($data, $filename, $content_type);
//}


//Attach Body
$mail->add_attachment($body, "", "text/html");


# send e-mail
$enviado = $mail->send();






//To Admin


$mail->parts = null;



$body = "<html><head><title>LE Test Results</title></head>



		<body><p><strong>Students LE Test Submission</strong></p>



		<p>The following are the students test results:</p>



		<p><table width='70%'style='margin-left:30px'>



		<tr><td width='30%'>Student Name:</td><td>$user_name</td></tr>



		<tr><td>Test Taken:</td><td>$test_name</td></tr>



		<tr><td>Date:</td><td>$committed_date</td></tr>



		<tr><td>Scores</td><td></td></tr>



		<tr><td colspan='2'><table width='80%' style='margin-left:50px'>";







foreach ($type_scores as $key=>$val)



{



	extract($val);



	$body .= "<tr><td width='30%'>$type_name</td><td>$type_score</td></tr>";



}







$body .= "</table></p><p>Best Regards,<br />



		<a href='http://www.thelearningedge.net/'>The Learning Edge</a>



		</p></body><html>";






# set all data slots

$mail->from = "noreply@thelearningedge.net";



//Admin email ID


$query = "SELECT tutor_email_id FROM user WHERE user_id=$user_id";
$res = mysql_query($query);
$row = mysql_fetch_assoc($res);


$mail->to = "t@gmail.com";




$mail->subject = "Students LE Test Submission";




//Attach PDF document
if($filename <> "")
{
	# append the attachment
	$mail->add_attachment($data, $filename, $content_type);
}


//Attach Body
$mail->add_attachment($body, "", "text/html");


# send e-mail
$enviado = $mail->send();






$_SESSION['msg'] = "<font color='green'>Test successfully committed</font>";



}


session_commit();



header("location:./home?test_id=$test_id");


?>

    Try adding the following at the top of the script to see if anything is happening that PHP can tell you about. Also check the spam/junk folder for the target email to see if it's ending up there.

    <?php
    ini_set('display_errors', 1); // set to 0 for production version
    error_reporting(E_ALL);
    // rest of script......
    ?>
    

      I got the following...

      Notice: Undefined variable: height in /home/iwori20/public_html/tests/_includes/class.PDF.php on line 107
      
      Notice: Undefined variable: height in /home/iwori20/public_html/tests/_includes/class.PDF.php on line 107
      
      Notice: Undefined variable: height in /home/iwori20/public_html/tests/_includes/class.PDF.php on line 107
      
      Notice: Undefined variable: height in /home/iwori20/public_html/tests/_includes/class.PDF.php on line 107
      
      Notice: Undefined variable: height in /home/iwori20/public_html/tests/_includes/class.PDF.php on line 107
      
      Notice: Undefined variable: height in /home/iwori20/public_html/tests/_includes/class.PDF.php on line 107
      
      Notice: Undefined variable: encode in /home/iwori20/public_html/tests/_includes/MailAttach.php on line 109
      
      Notice: Undefined variable: encode in /home/iwori20/public_html/tests/_includes/MailAttach.php on line 109
      
      Notice: Undefined variable: encode in /home/iwori20/public_html/tests/_includes/MailAttach.php on line 109
      
      Warning: Cannot modify header information - headers already sent by (output started at /home/iwori20/public_html/tests/_includes/class.PDF.php:107) in /home/iwori20/public_html/tests/commit_test.php on line 1250
      
      Notice: Undefined variable: template in /home/iwori20/public_html/tests/index.php on line 80
      
      Warning: Smarty error: unable to read resource: "" in /home/iwori20/public_html/tests/_includes/smarty/libs/Smarty.class.php on line 1092

        When I replace the mail to command to an email address instead of $email_id it sends to the emails, yet when I just display $email_id it prints on the page fine. Any ideas to what is going on when I try to send an email to $email_id ??

        Thanks!

          Write a Reply...