• Hi!
    I try to send email via Rest API internally, from my site (functions.php). My code:

    
    $body = array (
    	'_wpcf7' => 3240,
    	'_wpcf7_version' => '5.1.3',
    	'_wpcf7_unit_tag' => 'wpcf7-f3240-p3239-o1',
    	'_wpcf7_container_post' => 3239,
    	'your-name' => 'John'
    );
    
    $queue_request = new WP_REST_Request('POST', '/contact-form-7/v1/contact-forms/3240/feedback');
    $queue_request->add_header('Content-Type', 'multipart/form-data');
    $queue_request->add_header('Accept', 'application/json');
    $queue_request->set_body_params($body);
    $queue_request = rest_do_request($queue_request);
    
    if ($queue_request->is_error()) {
    	echo $queue_request->as_error()->get_error_message();
    }
    else {
    	print_r($queue_request->get_data());
    }
    

    Email arrives successfully but the tags are not replaced. Email contents look like this:

    
    Your name: [your-name]
    

    instead:

    
    Your name: John
    

    What am I doing wrong? When I do $request variable debug:

    
    \plugins\contact-form-7\includes\rest-api.php
    
    function wpcf7_rest_create_feedback( WP_REST_Request $request ) {
      $debug = print_r($request, true);
      ...
    }
    

    I get this result:

    
    WP_REST_Request Object
    (
        [method:protected] => POST
        [params:protected] => Array
            (
                [URL] => Array
                    (
                        [id] => 3240
                    )
    
                [GET] => Array
                    (
                    )
    
                [POST] => Array
                    (
                        [_wpcf7] => 3240
                        [_wpcf7_version] => 5.1.3
                        [_wpcf7_unit_tag] => wpcf7-f3240-p3239-o1
                        [_wpcf7_container_post] => 3239
                        [your-name] => John
                    )
    
                [FILES] => Array
                    (
                    )
    
                [JSON] => 
                [defaults] => Array
                    (
                    )
    
            )
    
        [headers:protected] => Array
            (
                [content_type] => Array
                    (
                        [0] => multipart/form-data
                    )
    
                [accept] => Array
                    (
                        [0] => application/json
                    )
    
            )
    
        [body:protected] => 
        [route:protected] => /contact-form-7/v1/contact-forms/3240/feedback
        [attributes:protected] => Array
            (
                [methods] => Array
                    (
                        [POST] => 1
                    )
    
                [accept_json] => 
                [accept_raw] => 
                [show_in_index] => 1
                [args] => Array
                    (
                    )
    
                [callback] => wpcf7_rest_create_feedback
            )
    
        [parsed_json:protected] => 1
        [parsed_body:protected] => 
    )
    
    • This topic was modified 4 years, 11 months ago by pepe80.
  • The topic ‘Sending email via Rest API internally’ is closed to new replies.