Opened 8 weeks ago
Last modified 5 hours ago
#64940 new enhancement
PHP mailer Exception Handler
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | trunk |
| Component: | Keywords: | has-patch | |
| Focuses: | Cc: |
Description
Wrap the phpmailer_init hook (do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) )) within a try-catch block in pluggable.php to ensure that exceptions during mail initialization are properly caught and logged.
Currently, if an exception occurs during the execution of the phpmailer_init hook (e.g., due to file permission issues when accessing attachments or embedded resources), the failure is not clearly logged, making debugging difficult. In a real-world scenario, a failure occurred due to restricted access to an uploads directory, but the root cause was not visible until the hook was wrapped in an exception block.
By handling exceptions at this point, errors such as "wp_mail failed" or file access issues (e.g., inability to access /wp-content/uploads) can be properly surfaced and logged, improving debuggability and reliability of the mail system.
Change History (3)
This ticket was mentioned in PR #11344 on WordPress/wordpress-develop by Kajori-Biswas.
8 weeks ago
#2
- Keywords has-patch added
This PR wraps the phpmailer_init hook (do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) )) in a try-catch block within wp_mail() to ensure that exceptions during mail initialization are properly caught and logged.
Currently, if an exception occurs during the execution of the phpmailer_init hook, it may fail silently or without sufficient logging, making it difficult to identify the root cause of mail delivery issues.
In real-world scenarios, failures can occur due to issues such as:
File permission errors (e.g., inaccessible files in wp-content/uploads)
Invalid attachments or embedded resources
Third-party hook implementations throwing exceptions
These failures can result in generic errors like "wp_mail failed" without exposing the underlying cause.
Solution:
Wrapped the phpmailer_init hook execution in a try-catch block
Ensured that any thrown exceptions are properly captured
Allows meaningful error messages to be logged for debugging purposes
Trac ticket: #64940
## Use of AI Tools