9951 explained code solutions for 126 technologies


phpmailerHow do I view the log for my PHPMailer emails?


To view the log for PHPMailer emails, you can use the $mail->SMTPDebug property. This property can be set to one of four values: 0 (no output), 1 (errors and messages), 2 (messages only), or 3 (verbose debug output).

For example, to view verbose debug output, you can use the following code:

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->SMTPDebug = 3;

// other settings

$mail->send();
echo "Message sent!";
?>

This will output something like the following:

SERVER -> CLIENT: 220 smtp.example.com ESMTP Postfix
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.example.com
SERVER -> CLIENT: 250-PIPELINING
SERVER -> CLIENT: 250-SIZE 10240000
SERVER -> CLIENT: 250-VRFY
SERVER -> CLIENT: 250-ETRN
SERVER -> CLIENT: 250-STARTTLS
SERVER -> CLIENT: 250-ENHANCEDSTATUSCODES
SERVER -> CLIENT: 250-8BITMIME
SERVER -> CLIENT: 250 DSN

The $mail->SMTPDebug property is set to 3 by default. It can be set to any of the four values before the $mail->send() method is called.

Helpful links

Edit this code on GitHub