PHP Curl Preauth Code

I finally got it working, the standard ways would not work. Here is what finally worked. I'm sure half of it could be trimmed out, if someone wants to optimize this please post the code back here.

This was with php 5.2.4. There are some issues with curl and open_dirs and safe mode in php. If you look at the php documentation you will see it.

PHP Code:

<?php
$zimbra_email_id ="123456"; // you need to know the id of the eamil to extract it.
$zm_base_url = "http://zimbra.example.com";
$zm_redirect_url = "/?id=".$zimbra_email_id."&view=html";
$zimbra_user = "zimbra_user";
//I have a group of functions that will build this, but I don't have time to post it now.
//but the url should look like this.