WordPress wp_mail错误地复制了电子邮件,如何防止此错误?

I made a custom code for sending out emails but when I trigger this code somehow it duplicates more than one emails, sometimes ranging from 2 to 8 emails at a time. I would appreciate any help given for this random glitch.

if(!empty(array_search('premium', $email_output)) && !empty($r_email) && strpos($r_email, '@') !== false && empty($_COOKIE['sentList']) && $_COOKIE['sentList'] == false){

$to = $r_email; 

$subject = 'subject'; 

ob_start();  
include trailingslashit( get_template_directory() ) . 'mailtemplate.php'; 
$body = ob_get_clean(); 

$headers = array('Content-Type: text/html; charset=UTF-8'); 

if( empty($_COOKIE['sentList']) && $_COOKIE['sentList'] == false ){ 
setcookie("sentList", true, time() + (60 * 5)); 

wp_mail( $to, $subject, $body, $headers ); 

}

}