OpenCart报错求助:PHP致命错误提示需指定收件人邮箱
Let's break down this issue and work through solutions step by step. First, let's anchor on the core error from your stack trace:
PHP Fatal error: Uncaught exception 'Exception' with message 'Error: E-Mail to required!' in /home/projects/public_html/system/storage/modification/system/library/mail.php:94
This error fires because OpenCart's mail class tries to send an email without a valid recipient address set. The stack trace shows this happens when the addOrderHistory method (for order #145031, status ID 2440) calls Mail->send().
Common Causes & Fixes
1. Empty Customer Email for Order #145031
The most probable issue is that the target order has no associated customer email address.
How to verify:
- Check the order in your OpenCart admin: Navigate to
Sales > Orders, find order 145031, and inspect the customer's email field. - Or run a quick database query (replace
oc_with your actual table prefix if needed):SELECT email FROM oc_order WHERE order_id = 145031;
Fix:
- If the email is empty, manually update it via the admin panel or SQL.
- To prevent future errors, add a validation check before sending emails in the order history code:
// In your modified order model file (vq2-system_storage_modification_catalog_model_checkout_order.php) $order_info = $this->getOrder($order_id); if (!empty($order_info['email'])) { $mail->setTo($order_info['email']); // Rest of your mail setup (subject, content, etc.) $mail->send(); } else { // Optional: Send a alert to your admin instead $mail->setTo($this->config->get('config_email')); $mail->setSubject('Missing Customer Email for Order #' . $order_id); $mail->setText('Order #' . $order_id . ' has no customer email attached. Please review it immediately.'); $mail->send(); }
2. VQMod Modification Broke Recipient Setup
Since your code uses VQCache files, a third-party modification may have removed or corrupted the code that sets the email recipient.
How to verify:
- Open
vq2-system_storage_modification_catalog_model_checkout_order.phpand go to line 1619 (whereMail->send()is called). Look for code like$mail->setTo($order_info['email']);right before the send call. If this line is missing, or$order_info['email']is being overwritten, that's the problem.
Fix:
- Compare the modified code with the original OpenCart
catalog/model/checkout/order.phpfile to restore the missing recipient setup logic. - Disable recently installed VQMod plugins related to order emails, test if the error resolves, then debug the problematic plugin's code.
3. Mail Class Validation Edge Case
Less likely, but worth checking: the mail class may be overly strict about recipient validation.
How to verify:
- Open
/home/projects/public_html/system/storage/modification/system/library/mail.phpand look at line 94. The exception is thrown here when thetoarray is empty. - Confirm that every call to
$mail->send()is preceded by a valid$mail->setTo()call with a non-empty email.
Fix:
- Add a safety check directly in the mail class (note: modifying core files isn't ideal, so prioritize fixing the calling code first):
// In mail.php, right before throwing the exception if (empty($this->to)) { // Fallback to admin email $this->setTo($this->config->get('config_email')); // Log the issue for debugging $this->log->write('Attempted to send email without recipient. Triggered by order ID: ' . $order_id); }
内容的提问来源于stack exchange,提问作者Frank Turtle

