邮件功能发送大量重复

I'm using the mail() function within a script to notify a sector of our company on some products.

The problem is they are receiving around 4-7 emails each time.

The mail() function is used in this function:

private function notifyOnCustoms($order_with_customs,$items){
        $headers = 'X-Mailer: PHP/' . phpversion();
        $email_address = 'support@ourcompany.com';
        $subject = "Order: {$order_with_customs['order_number']} contains Custom Products";
        $message = "In {$order_with_customs['order_number']}:
";
        $index = 0;

        foreach ($items as $item){
            if ($this->isCustom($item)){
                $filename = $this->getItemProductImage($item, $index);
                $productSKU = $item['sku'];
                preg_match('/\d{4,6})\.jpg$/', $filename, $match);
                $message.= "Product: {$productSKU}
Filename: {$filename}
{$match[1]}


";
            }
        }

        mail($email_address, $subject, $headers, $message);
        file_put_contents(HOLD_ORDER_PATH . $order_with_customs['order_number'] . '.json', json_encode($order_with_customs));
    }

and the method is used here:

if($this->hasCustomProducts($order['line_items'])){
            $this->notifyOnCustoms($order, $items);
            return "Order: {$order['order_number']} has custom items. Aborting the rest of the operations.";
        }

I also have some headers of the e-mails in case they are useful.

First e-mail:

X-Spam_Bar: /
X-Spam_Report: score=-0.0 tests=NO_RELAYS version=3.3.1 cmae=v=2.1 cv=ScrOKJhu c=1 sm=0 tr=0 a=7OsogOcEt9IA:10 a=5clJ4VCmAAAA:8 a=bK9mt9LiXbnJWSs7djgA:9 a=Q2D1RClc0W0A:10 a=dUXFEdsLsVoA:10
Envelope-To: support@ourcompany.com
X-Mt-Id: DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
X-Mt-Id: 7E4828DD7C3F75C0E68D1D91C27E3568B1A2A07A
Return-Path: <serveradmin@ourcompany.com>
X-Spam_Score: -0.0
Delivery-Date: Fri, 11 Mar 2016 14:13:20 -0500
Received: from n31.c04.mtsvc.net ([72.47.228.31]:38551) by n50.mail01.mtsvc.net with esmtps (UNKNOWN:AES128-SHA:128) (Exim 4.72) (envelope-from <serveradmin@ourcompany.com>) id 1aeSUx-0006HM-S0 for support@ourcompany.com; Fri, 11 Mar 2016 14:13:20 -0500
Received: from ourcompany.com by n31.c04.mtsvc.net with local (Exim 4.80.1) (envelope-from <serveradmin@ourcompany.com>) id 1aeSUr-0002ul-60 for support@ourcompany.com; Fri, 11 Mar 2016 11:13:19 -0800
X-Spam_Score_Int: 0
Message-Id: <E1aeSUr-0002ul-60@n31.c04.mtsvc.net>
Order: 6593 contains Custom Products

Last copy (6th email):

X-Spam_Bar: /
X-Spam_Report: score=-0.0 tests=NO_RELAYS version=3.3.1 cmae=v=2.1 cv=bZVSDo/B c=1 sm=0 tr=0 a=7OsogOcEt9IA:10 a=5clJ4VCmAAAA:8 a=bK9mt9LiXbnJWSs7djgA:9 a=Q2D1RClc0W0A:10 a=dUXFEdsLsVoA:10
Envelope-To: support@ourcompany.com
X-Mt-Id: DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
X-Mt-Id: 7E4828DD7C3F75C0E68D1D91C27E3568B1A2A07A
Return-Path: <serveradmin@ourcompany.com>
X-Spam_Score: -0.0
Delivery-Date: Fri, 11 Mar 2016 14:04:18 -0500
Received: from n19.c04.mtsvc.net ([72.47.228.19]:59467) by n50.mail01.mtsvc.net with esmtps (UNKNOWN:AES128-SHA:128) (Exim 4.72) (envelope-from <serveradmin@ourcompany.com>) id 1aeSME-0005is-LZ for support@ourcompany.com; Fri, 11 Mar 2016 14:04:18 -0500
Received: from ourcompany.com by n19.c04.mtsvc.net with local (Exim 4.80.1) (envelope-from <serveradmin@ourcompany.com>) id 1aeSM7-0007G2-N0 for support@ourcompany.com; Fri, 11 Mar 2016 11:04:17 -0800
X-Spam_Score_Int: 0
Message-Id: <E1aeSM7-0007G2-N0@n19.c04.mtsvc.net>
Order: 6593 contains Custom Products

Edit: Including calling function

public function prepareForAPI($order){
        $mOrder = $order;
        $mItems = $this->filterItems($order['line_items']);
        $mOrder['line_items'] = $mItems;

        if($this->hasCustomProducts($mItems)){
            file_put_contents('debug/debug_info.txt', "
Order with custom products.
", FILE_APPEND | LOCK_EX);
            $this->notifyOnCustoms($mOrder, $mItems);
            exit;
        }
        else{
            file_put_contents('debug/debug_info.txt', "
Sending order :D
", FILE_APPEND | LOCK_EX);
            return $this->pushToAPI($this->formatToAPI($mOrder));
        }
    }