2026年7月2日
2026年7月2日
WooCommerceの注文メールが届かない問題を解決する方法
はじめに
WooCommerceの注文確認メールが届かない・迷惑メールに入る・管理者通知だけ届かない問題は、サーバーのSMTP設定不備・差出人アドレスの設定ミス・メールプロバイダーのスパムフィルターが原因であることが多いです。
症状・原因
- 顧客への注文確認メールが届かない
- 管理者への新規注文通知だけが届かない
- メールが迷惑メールフォルダに入る
- 特定のメールアドレス(GmailやYahoo)にだけ届かない
解決手順
ステップ1:メール送信の問題を診断する
# WP-CLI でテストメールを送信
wp eval "
\$result = wp_mail(
'test@example.com',
'WooCommerce メールテスト',
'このメールが届けば wp_mail は正常です。',
['Content-Type: text/plain; charset=UTF-8']
);
echo \$result ? '送信成功' : '送信失敗';
"
# WooCommerce のメールクラスを確認
wp eval "
\$emails = WC()->mailer()->get_emails();
foreach (\$emails as \$id => \$email) {
printf('%s: enabled=%s, to=%s' . PHP_EOL,
\$id, \$email->is_enabled() ? 'yes' : 'no', \$email->get_recipient()
);
}
"
# メールログを確認(WC Email Log プラグイン使用時)
wp eval "
global \$wpdb;
\$logs = \$wpdb->get_results(
\"SELECT * FROM {$wpdb->prefix}wc_email_log ORDER BY timestamp DESC LIMIT 10\"
);
foreach (\$logs as \$log) {
echo \$log->timestamp . ': ' . \$log->subject . PHP_EOL;
}
"
ステップ2:SMTP でメールを確実に送信する
// functions.php: SMTPでメールを送信(SendGrid / Gmail / Amazon SES)
add_action('phpmailer_init', function(PHPMailer\PHPMailer\PHPMailer $phpmailer): void {
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.sendgrid.net';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 587;
$phpmailer->Username = 'apikey';
$phpmailer->Password = defined('SENDGRID_API_KEY') ? SENDGRID_API_KEY : '';
$phpmailer->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
$phpmailer->From = get_option('woocommerce_email_from_address');
$phpmailer->FromName = get_option('woocommerce_email_from_name');
});
// wp-config.php に APIキーを定義
// define('SENDGRID_API_KEY', 'SG.xxxxxxxxxx');
// メール送信失敗時のログ
add_action('wp_mail_failed', function(WP_Error $error): void {
WC()->logger()->error(
'wp_mail failed: ' . $error->get_error_message(),
['source' => 'wc-email']
);
});
ステップ3:WooCommerce メールのヘッダーと差出人を修正する
// functions.php: WooCommerceメールの差出人・返信先をカスタマイズ
// ① 差出人アドレスを設定
add_filter('woocommerce_email_from_address', fn() => 'noreply@example.com');
add_filter('woocommerce_email_from_name', fn() => 'ショップ名');
// ② メールヘッダーを追加(迷惑メール対策)
add_filter('woocommerce_email_headers', function(string $headers, string $id, WC_Order $order): string {
$headers .= 'Reply-To: support@example.com' . "\r\n";
$headers .= 'X-Mailer: WooCommerce' . "\r\n";
return $headers;
}, 10, 3);
// ③ 特定のメールタイプだけBCCを追加
add_filter('woocommerce_email_headers', function(string $headers, string $id): string {
if ($id === 'new_order') {
$headers .= 'BCC: archive@example.com' . "\r\n";
}
return $headers;
}, 10, 2);
// ④ 管理者通知の送信先を変更
add_filter('woocommerce_new_order_email_allows_resend', '__return_true');
add_filter('woocommerce_email_recipient_new_order', function(string $recipient): string {
return 'orders@example.com, backup@example.com';
});
ステップ4:メールテンプレートをカスタマイズする
// functions.php: WooCommerceメールの内容をカスタマイズ
// ① メール件名を変更
add_filter('woocommerce_email_subject_customer_processing_order',
function(string $subject, WC_Order $order): string {
return sprintf('【ご注文確認】%s からのご注文 #%d',
get_bloginfo('name'), $order->get_id());
}, 10, 2
);
// ② メール本文にカスタム内容を追加
add_action('woocommerce_email_order_details', function(WC_Order $order, bool $sent_to_admin): void {
if (!$sent_to_admin) {
echo '<p>ご注文ありがとうございます。発送まで1〜3営業日お待ちください。</p>';
}
}, 5, 2);
// ③ メールフッターをカスタマイズ
add_filter('woocommerce_email_footer_text', function(string $text): string {
return $text . '<br>お問い合わせ:support@example.com | Tel: 03-xxxx-xxxx';
});
# テンプレートをテーマにコピーしてカスタマイズ
# オリジナル: wp-content/plugins/woocommerce/templates/emails/
# カスタム: wp-content/themes/your-theme/woocommerce/emails/
mkdir -p wp-content/themes/my-theme/woocommerce/emails/
cp wp-content/plugins/woocommerce/templates/emails/customer-processing-order.php \
wp-content/themes/my-theme/woocommerce/emails/
# WooCommerce メールをプレビュー(管理画面)
# WooCommerce → 設定 → メール → 各メール → プレビュー
ステップ5:メール到達率を改善する
// functions.php: SPF・DKIM・DMARCの設定確認とメール改善
// ① メールに List-Unsubscribe ヘッダーを追加
add_filter('woocommerce_email_headers', function(string $headers, string $id, WC_Order $order): string {
$unsubscribe_url = wc_get_account_endpoint_url('orders');
$headers .= 'List-Unsubscribe: <' . esc_url($unsubscribe_url) . '>' . "\r\n";
return $headers;
}, 10, 3);
// ② メール送信をキューに入れて非同期処理
add_filter('woocommerce_defer_transactional_emails', '__return_true');
// ③ WooCommerce メールの再送信機能を追加
add_action('woocommerce_order_actions', function(array $actions): array {
$actions['send_order_confirmation'] = '注文確認メールを再送信';
return $actions;
});
add_action('woocommerce_order_action_send_order_confirmation', function(WC_Order $order): void {
WC()->mailer()->emails['WC_Email_Customer_Processing_Order']->trigger($order->get_id());
$order->add_order_note('注文確認メールを手動で再送信しました。');
});
# SPF レコードを確認(メール到達率改善)
nslookup -type=TXT example.com | grep spf
# DKIM・DMARC の設定確認
nslookup -type=TXT _dmarc.example.com
nslookup -type=TXT default._domainkey.example.com
# MXToolbox でメール設定を総合チェック
# https://mxtoolbox.com/SuperTool.aspx でドメインを調査
注意事項
- WordPressのデフォルトの
mail()関数は多くのホスティング環境でスパム判定されやすいです。SendGrid・Amazon SES・Mailgunなどの外部SMTPサービスの使用を強く推奨します - WooCommerceのメールテンプレートをテーマにコピーする場合、WooCommerceのバージョンアップ時にテンプレートが古くなる可能性があります。
WooCommerce → ステータス → テンプレートで古いテンプレートがないか定期的に確認してください - 差出人アドレス(From)はSPFレコードで認証されたドメインのアドレスを使ってください。認証されていないアドレスからのメールは迷惑メールに分類されます
まとめ
WooCommerceメール未到達の解決は①wp_mail()でテスト送信しSMTP設定の問題を切り分け、②phpmailer_initフックでSendGrid/Amazon SESのSMTP設定を実装しwp_mail_failedでエラーをログ、③woocommerce_email_from_addressとwoocommerce_email_headersで差出人・Reply-To・BCCを設定、④メールテンプレートをテーマにコピーして件名・本文・フッターをカスタマイズ、⑤SPF/DKIM/DMARCのDNSレコードを設定してメール到達率を向上させます。