TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   ob_get_clean() doesn't work properly (http://www.talkphp.com/general/5985-ob_get_clean-doesnt-work-properly.html)

Avarus 09-17-2011 09:51 AM

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);
        }


tony 09-18-2011 11:28 PM

It seems that is a problem with the email provider that you are receiving the email from. But I don't know much about how email are parsed by the email providers. It is a wild west. Have you tried sending test emails to different accounts, for example seeing to see how hotmail, gmail, yahoo, or any other one parses the incoming html emails to see it is not a problem with your script, but the receiving servers.

wGEric 09-19-2011 06:34 PM

You need to do old school HTML and inline styles for emails. Unless it is a really simple email it will not look the same in all email clients. Take a look at this site to see what is supported:

http://www.email-standards.org/

Here is a site that will test HTML emails in multiple clients:

http://litmus.com/


All times are GMT. The time now is 06:37 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0