cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: POST problem

From: Stijn De Maesschalck <stijn_dm_at_pi.be>
Date: Mon, 31 May 2004 21:11:06 +0200

Thanks,

I now at least get some feedback on the screen. But although all login
information is correct, I don't get passed the login screen. I've imported
your suggestions into another file http://info.czar.be/openwebmail2.php
where you also can see the headers. I know that the webmail application
doesn't use any cookies.

Any other idea of what might cause the problem?

Yours,
Stijn DM

----- Original Message -----
From: "Alan Storm" <gliff_at_rochester.rr.com>
To: "using curl with PHP" <curl-and-php_at_cool.haxx.se>
Sent: Monday, May 31, 2004 5:32 AM
Subject: Re: POST problem

> On 5/30/04, Stijn De Maesschalck typed
>
> >If you want, you can take a look on
> >http://info.czar.be/webmail.php. I've put the HTML code
> >there along with the PHP code I'm using.
>
> Your POST data isn't being sent.
>
> CURLOPT_POSTFIELDS expects a URL encoded query string, not an
> associative array. Try the code listed below my sig (changes to your
> code marked in comments)
>
> If your webmail app. requires cookies, you're going to need to muck
> about with those options as well.
>
> --
> Alan Storm
> http://www.gliff.org
>
> +------------------------------------------------------------+
> <?php
> //this function is passed an array, and returns a
> //url encoded query string.
> function encodeQueryString($array){
> if(!is_array($array)){
> die("Encode Post Array expects an array");
> }
>
> $retValue = '';
> for(reset($array);$key=key($array);next($array)){
> $retValue .= $key."=".urlencode($array[$key])."&";
> }
> //zap last &
> $retValue = substr($retValue, 0, -1);
> return $retValue;
> }
> ?>
> <?php
>
> $postdata['imapuser']="test";
> $postdata['pass']="12345";
> $postdata['actionid']="105";
> $postdata['url']="http://webmail.info.czar.be/horde/login.php";
> $postdata['mailbox']="INBOX";
> $postdata['port']="143";
> $postdata['server']="localhost";
> $postdata['namespace']="";
> $postdata['maildomain']="info.czar.be";
> $postdata['protocol']="imap/notls";
> $postdata['realm']="info.czar.be";
> $postdata['folders']="INBOX.";
> $postdata['submit']="open+webmail";
>
> //pass associative array to function that will
> //create an encoded query string
> $postdata = encodeQueryString($postdata);
>
> $ch = curl_init();
>
> curl_setopt($ch, CURLOPT_VERBOSE,1);
> curl_setopt($ch, CURLOPT_URL,
> "http://webmail.info.czar.be/horde/login.php");
> curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
> curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_HEADER, 1);
> curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
>
>
> // execute a POST request
>
> $result = curl_exec ($ch);
> curl_close($ch);
> print($result);
> ?>
> +------------------------------------------------------------+
>
Received on 2004-05-31