I want to login into my Horde Webmail automatically through phpcurl and then display all my Emails. So far my login works perfect. I login with Credentials and Cookies.
What's the Problem?
I get my Dashboard displayed but without any Data. Here is a Screenshot how it looks like:
What Error Output do I get?
In the Console it says:
Failed to load resource: the server responded with a status of 404 (Not Found)
Here a Screenshot of my Console:
What Code do I use so far?
//Data
$webmail_login = "http://webmail.licht-austria.at/login.php";
$webmail_mailbox = "http://webmail.licht-austria.at/imp/dynamic.php?page=mailbox";
$login = "";
$password = '';
$postdata = "login_post=1&horde_user=$login&horde_pass=$password&horde_select_view=auto&new_lang=de_DE";
//Curl Login POST
$ch = curl_init();
$agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL, $webmail_login );
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
$result = curl_exec($ch);
//Until here it works i logged in
//Curl Mailbox GET
curl_setopt($ch, CURLOPT_URL, $webmail_mailbox);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$data = curl_exec($ch);
echo $data;
How does my Code work?
In the first steps I use my Credentials and Login through POST into my Webmail. The PostData ist correct and I can Login. After webmail.at/login.php is finished, I get redirect to my Inbox (webmail.at/imp/dynamic.php?page=mailbox). The webmail uses GET Method now to get all the Emails and Stuff and at this moment I get the 404 Errors.
Failed to load resource: the server responded with a status of 404 (Not Found)
well, this error is not related to the curl, it's related to loading website resources into you web page .
to solve this you may work around it by :
echo '<base href="http://www.example.com" />' . $data;
however, it's not recommended to do this.
it will be better that you re-manipulate your response data ,
for example , if the response is a html , parse it using Dom library for example , or simply using regex , and if it a json response rebuild new simple ui to view your results .