php curl send post command to MW - a future wordpress plugin ( if it will work :) )


Active Member
Hy guys,
i am trying to develop an open source plugin for wordpress to login into mailwizz. When it will work i release this plugin totally free but i need some support :)

Explanation :
wordpress hosted on ""
mw hosted on ""

2 different domains

mw side i dont want touch nothing (csrf must also be enabled)

in my dev lab , i pass username, password and got csrf token per session but in my output i get this result ( see image attached ) .
In address bar i keep my local address ( wordpress ) and not the mw site and all link redirect to my local address ( eg. )

any suggestion ?

this is my code

$ch = curl_init("");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$response = curl_exec($ch);

$dom = new DomDocument;
$tags = $dom->getElementsByTagName('input');
for($i = 0; $i < $tags->length; $i++) {
        $grab = $tags->item($i);
        if($grab->getAttribute('name') === 'csrf_token') {
                $token =  $grab->getAttribute('value');
//echo $token; /debug

$data = array(
        "CustomerLogin[email]" => "myusername",
        "CustomerLogin[password]" => "mypassword",
        "csrf_token" => $token,

curl_setopt($ch, CURLOPT_URL, "");
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
echo $response;