WordPress: inviare un form remoto

WordPress: inviare un form remoto

In WordPress è semplice inviare un form remoto.

La soluzione è la seguente:


function my_send_remote_form( $url, $data ) {
    $args = array(
        'method' => 'POST',
        'timeout' => 5,
        'headers' => array(
            'content-type' => 'application/x-www-form-urlencoded'
        ),
        'cookies' => array(),
        'body' => $data
    );

    $response = wp_remote_post( $url,  $args );
    if( !is_wp_error( $response ) ) {
        return $response;
    } else {
        return false;
    }
}

Torna su