PHP 8.x TypeError + empty From Address
-
Hi Zoho Mail Team,
I’m writing to report a compatibility issue with the Zoho Mail plugin (v1.6.3)
running on PHP 8.3 + WordPress. After OAuth authentication succeeds, the
From Email Address dropdown remains empty, and the plugin throws PHP errors. Root Cause (Two Issues) Issue 1: PHP 8.x Strict TypingThe plugin uses
count()andforeach()onsendMailDetailswithout
null-checking. In PHP 7.x this silently returned 0 / skipped, but PHP 8.x
throws TypeError:Line 380: count($jsonbodyAccounts->data[$i]->sendMailDetails)
→ TypeError: count(): Argument #1 must be Countable|array, null givenLine 618: foreach ($account->sendMailDetails as $mailDetail)
→ Warning: foreach() argument must be array|object, null givenIssue 2: Zoho API No Longer Returns sendMailDetails
When calling
https://mail.zoho.com/api/accountswith a valid OAuth token,
the response no longer includes thesendMailDetailsfield for some account
types. The account object hasprimaryEmailAddress(string) andemailAddress(array of objects), butsendMailDetailsis simply absent.This means even after fixing Issue 1, the dropdown has no data to display. Fix Applied
Three changes in zohoMail.php: Change 1 — Null-safe count() (line ~380)
`php<br>// Before<br>for ($j = 0; $j < count($jsonbodyAccounts->data[$i]->sendMailDetails); $j++) {</p> <p>// After<br>if (is_array($jsonbodyAccounts->data[$i]->sendMailDetails)<br>&& count($jsonbodyAccounts->data[$i]->sendMailDetails) > 0) {<br>for ($j = 0; $j < count($jsonbodyAccounts->data[$i]->sendMailDetails); $j++) {</p> <p></p> <p>Change 2 — Null-safe foreach() (line ~618)</p> <p>// Before<br>foreach ($account->sendMailDetails as $mailDetail) {</p> <p>// After<br>if (is_array($account->sendMailDetails) && count($account->sendMailDetails) > 0) {<br>foreach ($account->sendMailDetails as $mailDetail) {</p> <p></p> <p>Change 3 — Fallback to primaryEmailAddress (lines ~391 and ~635)</p> <p>// When sendMailDetails is empty, use primaryEmailAddress as fallback<br>} elseif (!empty($account->primaryEmailAddress)) {<br>$fromAddress = $account->primaryEmailAddress;<br>// … render option<br>}</p> <p></p> <p>Environment</p> <ul> <li>WordPress: latest</li> <li>PHP: 8.3.32 (NTS)</li> <li>Plugin: Zoho Mail 1.6.3</li> <li>Server: Debian 10, Nginx</li> </ul> <p>Suggested Permanent Fix</p> <p>Consider using <code>primaryEmailAddress</code> as the primary data source (it’s always<br>a string and always present), falling back to iterating <code>emailAddress</code> array<br>or <code>sendMailDetails</code> if needed. This would be more robust across Zoho API<br>versions.</p> <p>Thanks,</p>
You must be logged in to reply to this topic.