View Single Post
Old 09-17-2011, 09:51 AM   #1 (permalink)
Avarus
The Visitor
 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Avarus is on a distinguished road
Default ob_get_clean() doesn't work properly

Hi guys! For a newletter project I'm using ob_start() and ob_get_clean() for recording some HTML/CSS/PHP code, but the output is quite weird. When I buffer the following:

Code:
<html>
<head>
<title><?php echo $list->title; ?></title>
<style type="text/css">

#text h1{
    font: bold 16px Verdana, Geneva, sans-serif;
    margin: 0px;
    text-align: center;
}

#text a{
    color: #4c79ac;
    text-decoration: none;
}
</style>
</head>
<body>
{some content here}
</body>
</html>
i get as output:

Code:
#text h1{
    font: bold 16px Verdana, Geneva, sans-serif;
    margin: 0px;
    text-align: center;
    color: #4c79ac;
    text-decoration: none;
}
</style>
</head>
<body>
{some content here}
</body>
</html>
        </u></body></html>
As you can see, it's not quite what it should be. The first few lines are not buffered, the CSS gets messed up and some tags are added at the end. Could any of you help me with this? I've tried removing all PHP and CSS, but that didn't make any difference...

EDIT: ok, just after posting I found out there was an issue in the mail headers, so I partially fixed it. The problem now is: when the buffer output is being mailed, everything before the <body> tag is wiped. But only when it is mailed, when I view the output online, it's all good. Here is the script I use to send the mail:

Code:
public function send($id) {
		$date = date("Y-m-d");
		$query = mysql_query("SELECT * FROM aquanieuws WHERE id = '".$id."'", $this->database);
		$list = mysql_fetch_object($query);
		$file = unserialize(urldecode($list->file));
		$hash = md5(date("r", time()));
		$to = "**************";
		$subj = $list->title;
		$msg = modules::build($id);
		$headers = 'From: Aquamail <*******>' . "\r\n";
		$headers .= 'Reply-To: ************' . "\r\n";
		$headers .= 'X-Mailer: PHP/' . phpversion();
		$headers .= 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-Type: multipart/mixed; boundary="'.$hash.'"' . "\r\n";
		$headers .= 'This is a multi-part message in MIME format.' . "\r\n";
		$headers .= '--'.$hash.'' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		$headers .= 'Content-Transfer-Encoding: 7bit' . "\r\n";
		$headers .= $msg . "\r\n";
		if(!empty($file["name"])) {
			$file_path = "../upload/".$id."/".$file["name"]."";
			$attachment = chunk_split(base64_encode(file_get_contents($file_path)));
			$headers .= '--'.$hash.'' . "\r\n";
			$headers .= 'Content-Type: '.$file["type"].'; name="'.$file["name"].'"' . "\r\n";
			$headers .= 'Content-Transfer-Encoding: base64' . "\r\n";
			$headers .= 'Content-Disposition: attachment; filename="'.$file["name"].'"' . "\r\n";
			$headers .= ''.$attachment.'\r\n';
		}
						
		if(mail($to, $subj, "", $headers)) {
			return(1);
		}
		return(0);
		mysql_query("UPDATE aquanieuws SET date = '".$date."', sent = '1' WHERE id = '".$id."'", $this->database);
	}

Last edited by Avarus : 09-17-2011 at 10:14 AM.
Avarus is offline  
Reply With Quote