Azure / Azure/wordpress-linux-appservice

[Bug] WooCommerce attachment emails fail on Azure App Service — ABSPATH resolves incorrectly in containerized WordPress (v1.2.1)

Open
#219 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HCL
Stars
138
Forks
84
PR merge metrics
No merged PRs in 30d

Description

## Summary

On Azure App Service containerized WordPress deployments, WooCommerce order
notification emails that include attached invoice PDFs fail silently with the
following error in the Azure Email Logs:

Request body validation error. ContentBytes invalid. Should be base64

Basic emails (contact forms, password resets) send successfully. Only emails
with attachments are affected.

---

## Root Cause

In `admin/mailer/class-azure_app_service_email-controller.php`, the
`generate_request_body()` method resolves attachment paths using `ABSPATH`:

```php
foreach ($filePaths as $path) {
if ($path[0] !== '/') {
$path = ABSPATH . trim($path);
}
if (file_exists($path)) { ... }
}
```

On Azure App Service containerized WordPress, `ABSPATH` resolves to
`/var/www/html` while the actual running WordPress root is
`/var/www/wordpress`. The path resolves incorrectly, `file_exists()` returns
false, the attachment is silently dropped, and the ACS REST API rejects the
malformed request body.

The "ContentBytes invalid" error is a red herring — the real issue is a path
mismatch between ABSPATH and the actual WordPress root inside the container.

---

## Steps to Reproduce

1. Deploy WordPress on Azure App Service (Linux, containerized)
2. Install WooCommerce and the App Service Email plugin v1.2.1
3. Place a test order
4. Observe that the New Order and Processing Order emails never arrive
5. Check Azure Email Logs — error reads "ContentBytes invalid. Should be base64"

---

## Expected Behavior

WooCommerce order notification emails send successfully with attached invoice
PDFs via Azure Communication Services.

---

## Actual Behavior

Emails with attachments fail. Emails without attachments succeed.

---

## Proposed Fix

Replace `ABSPATH` with a path derived from `WP_CONTENT_DIR`, which correctly
resolves to the active WordPress root regardless of container layout. Also
adds an empty path guard and immediate trim to prevent related edge case
failures:

```php
foreach ($filePaths as $path) {
$path = trim($path);
if (empty($path)) { continue; }
if ($path[0] !== '/') {
$wp_root = rtrim(str_replace('wp-content', '', WP_CONTENT_DIR), '/');
$path = $wp_root . '/' . $path;
}
if (file_exists($path)) { ... }
}
```

A community fix including a PowerShell automation script and full root cause
analysis is documented here:
https://github.com/JONeillSr/Repair-AppServiceEmailAttachmentPatch

---

## Environment

| Component | Version |
|---|---|
| App Service Email Plugin | v1.2.1 |
| WordPress | 7.x |
| WooCommerce | 8.x+ |
| Azure App Service | Linux, containerized |
| PHP | 8.x |

---

## Workaround

Apply the patch manually via SSH or using the PowerShell automation script
linked above. The fix is confirmed working in production.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.