WordPress sending emails continuously. How to stop it?

The problem

I think the problem here is that you’re generating an infinite loop, by placing wp_mail() inside the $phpmailer->action_function callback, that fires after each email.

Each time you send an email with wp_mail(), you call wp_mail() again, and again, and again … etc

Possible workaround

You should instead use, for example, the following approach:

function twp_mail_action($result, $to, $cc, $bcc, $subject, $body){

    // Here we remove the phpmailer_init action callback, to avoid infinite loop:
    remove_action( 'phpmailer_init', 'wpse_phpmailer_init' );

    // Send the test mail:
    wp_mail( '[email protected]', 'The subject', 'The message' );

    // Here we add it again
    add_action( 'phpmailer_init', 'wpse_phpmailer_init' );

}

add_action( 'phpmailer_init', 'wpse_phpmailer_init' );

function wpse_phpmailer_init( $phpmailer )
{
    $phpmailer->action_function = 'twp_mail_action';
} 

Note that this is untested, so be careful testing this only on a server where you can clear the mail queue yourself, if mistakes are made in the testing 😉

Better:

Log your tests to a file instead, for example.

Limit the delivery of emails

It would be interesting if we could limit the number of sent emails, per page load, while doing tests.

Here’s one idea for such a plugin:

<?php
/**
 * Plugin Name: Limit Delivered Emails
 * Description: Set an upper limit to number of sent emails per page load.
 * Plugin URI:  https://wordpress.stackexchange.com/a/193455/26350
 */
add_action( 'phpmailer_init', function( $phpmailer )
{
    $max_emails_per_page_load = 10; // <-- Edit this to your needs!

   if( did_action( 'phpmailer_init' ) > $max_emails_per_page_load )
       $phpmailer->ClearAllRecipients();

} );

where we clear the to/cc/bc fields, with the ClearAllRecipients() method, to stop the email delivery.

We could also throw an uncaught error with:

throw new \phpmailerException( __( 'Too many emails sent!' ) );

instead of using:

$phpmailer->ClearAllRecipients();

This is related to my answer here regarding the use of the PHPMailer class.