WooCommerce - 在创建订单时发送电子邮件

时间:2016-02-09 09:27:17

标签: php html wordpress email woocommerce

我正在尝试在下订单时向多个电子邮件地址发送电子邮件。我正在使用 woocommerce_thankyou 钩子。但电子邮件根本就不发送。

final int id = getId();
 if (id != NO_ID) {
        out.append(" #");
        out.append(Integer.toHexString(id));

add_action( 'woocommerce_thankyou', function( $order_id ){ $order = new WC_Order( $order_id ); $paymentType = $order->payment_method_title; $firstName = $order->billing_first_name; $lastName = $order->billing_last_name; $billing_address = $order->billing_address_1; $billing_address2 = $order->billing_address_2; $billing_postcode = $order->billing_postcode; $billing_city = $order->billing_city; $billing_country = $order->billing_country; $billing_email = $order->billing_email; $billing_phone = $order->billing_phone; $totalRefunded = $order->get_total_refunded(); $totalTaxRefunded = $order->get_total_tax_refunded(); $totalShippingRefunded = $order->get_total_shipping_refunded(); $total = $order->get_order_currency() . $order->get_total(); $notes = $order->get_customer_order_notes(); $company = $order->billing_company; $orderItems = $order->get_items(); $subject = 'Order ' . $order_id . ' was placed'; $message = ''; $message .= "Payment Type: $paymentType<br>"; $message .= "First Name: $firstName<br>"; $message .= "Last Name: $lastName<br>"; $message .= "Adress1: $billing_address<br>"; $message .= "Adress2: $billing_address2<br>"; $message .= "Post Code: $billing_postcode<br>"; $message .= "City: $billing_city<br>"; $message .= "Country: $billing_country<br>"; $message .= "Email: $billing_email<br>"; $message .= "Phone: $billing_phone<br>"; $message .= "Total Refunded: $totalRefunded<br>"; $message .= "Total Tax Refunded: $totalTaxRefunded<br>"; $message .= "Company: $company<br>"; $message .= "Order Notes: $notes->post_excerpt<br>"; $message .= "Total Shipping Refunded: $totalShippingRefunded<br><br>"; foreach($orderItems as $product) { $message .= $product['name'] . ' x' . $product['qty'] . '<br>'; } $message .= "<br>Total: $total"; $headers = "Content-type: text/html; charset=windows-1251 \r\n"; $headers .= 'From: post@test.com' . "\r\n" . "Reply-To: $billing_email" . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail(get_option('ordemails'), $subject, $message, $headers); }); 是一个字符串,其中包含以逗号分隔的电子邮件地址(test@test.com,test2@test.com)

0 个答案:

没有答案