Phpmailer debug

PHPMailer Debugging

When using PHPMailer library for sending emails in PHP, you can enable debug output to help diagnose any issues that may occur during the email sending process.

Enabling Debug Mode

To enable debug mode in PHPMailer, you can use the SMTPDebug property. This property takes an integer value that represents the level of debug output you want to see. Here are some common values:

  • 0: No debug output (default)
  • 1: Output errors only
  • 2: Output errors and messages
  • 3: Output errors, messages, and connection status
  • 4: Output everything, including protocol-level debug information

Example Usage

Here is an example of setting up PHPMailer with debug mode enabled:


  // Include PHPMailer library
  require 'path/to/PHPMailer.php';
  
  // Create a new PHPMailer instance
  $mailer = new PHPMailer\PHPMailer\PHPMailer();
  
  // Set debug mode to level 2
  $mailer->SMTPDebug = 2;
  
  // Continue with the rest of the email sending process
  // ...
  

With debug mode enabled, you will see debug output in your browser’s console or in the PHP error log, depending on your configuration.

Leave a comment