Troubleshooting

Common Issues

Emails Not Being Sent

Symptom: send() returns true but no email is received.

Solutions:

  1. Check spam/junk folder — emails from WordPress often land in spam
  2. Install an SMTP plugin — WordPress's default mail() function is unreliable
  3. Verify SMTP settings — check your SMTP plugin's connection test feature
  4. Check email logs — use Post SMTP or WP Mail SMTP's logging feature
// Debug: verify wp_mail is working
$result = wp_mail('[email protected]', 'Test', 'Testing wp_mail directly');
var_dump($result); // Should be true

send() Returns false

Symptom: The send() method returns false.

Solutions:

  1. Check recipients — ensure to() was called with valid email addresses
  2. Check wp_mail errors — hook into wp_mail_failed:
add_action('wp_mail_failed', function (WP_Error $error) {
    error_log('wp_mail failed: ' . $error->get_error_message());
});
  1. Verify PHP mail configuration — check php.ini for sendmail_path

HTML Content Shows as Plain Text

Symptom: Email recipients see raw HTML tags instead of formatted content.

Solutions:

The Content-Type: text/html; charset=UTF-8 header is automatically set when using html(), view(), or component body methods. If it's still showing as plain text:

  1. Check for conflicting plugins — some plugins override the content type
  2. Verify headers in build output:
$built = $mail->build();
var_dump($built['headers']); // Should contain Content-Type header

View Templates Not Rendering

Symptom: view() returns empty content.

Solutions:

  1. Check the template path:
$mail->templatePath('/absolute/path/to/templates');
// Template file should be at: /absolute/path/to/templates/{name}.php
  1. Verify the file exists:
$templateFile = '/path/to/templates/my-template.php';
var_dump(file_exists($templateFile)); // Should be true
  1. Check for PHP errors in the template — syntax errors will cause ob_get_clean() to return empty

MailManager Not Resolving from Container

Symptom: $app->make(MailManager::class) throws an error.

Solutions:

  1. Register the ServiceProvider:
$app->register(new MailServiceProvider());
  1. Ensure registration happens before resolution — register in plugin bootstrap, not in a hook that fires later

Attachments Not Included

Symptom: Email sends successfully but attachments are missing.

Solutions:

  1. Use absolute paths:
// Good: Absolute path
$mail->attach('/var/www/html/wp-content/uploads/invoice.pdf');

// Bad: Relative path — may not resolve correctly
$mail->attach('uploads/invoice.pdf');
  1. Verify file exists:
$path = '/path/to/file.pdf';
if (file_exists($path)) {
    $mail->attach($path);
}
  1. Check file permissions — WordPress process needs read access

From Address Being Overridden

Symptom: The from address set via from() is ignored.

Solutions:

Some SMTP plugins force the from address. Check:

  1. Your SMTP plugin's "Force From Email" setting
  2. WordPress filters on wp_mail_from and wp_mail_from_name
// Debug: check what filters are active
var_dump(has_filter('wp_mail_from'));
var_dump(has_filter('wp_mail_from_name'));

Getting Help