我为发送电子邮件做了一个自定义代码,但是当我触发该代码时,它会重复复制多个电子邮件,有时一次是2到8封电子邮件。对于这种随机故障,我将不胜感激。
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 );
}
}