我在脚本中使用mail()
函数来通知我们公司的部分产品。
问题是他们每次都会收到大约4-7封电子邮件。
此功能使用mail()
功能:
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']}:\n";
$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}\nFilename: {$filename}\n{$match[1]}\n\n\n";
}
}
mail($email_address, $subject, $headers, $message);
file_put_contents(HOLD_ORDER_PATH . $order_with_customs['order_number'] . '.json', json_encode($order_with_customs));
}
,这里使用的方法是:
if($this->hasCustomProducts($order['line_items'])){
$this->notifyOnCustoms($order, $items);
return "Order: {$order['order_number']} has custom items. Aborting the rest of the operations.";
}
我也有一些电子邮件标题,以防它们有用。
首封电子邮件:
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
最后一份(第6封电子邮件):
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
编辑:包含通话功能
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', "\nOrder with custom products.\n", FILE_APPEND | LOCK_EX);
$this->notifyOnCustoms($mOrder, $mItems);
exit;
}
else{
file_put_contents('debug/debug_info.txt', "\nSending order :D\n", FILE_APPEND | LOCK_EX);
return $this->pushToAPI($this->formatToAPI($mOrder));
}
}