Search code examples
loggingphpmailer

View log PHPMailer


I use oh-mailer 5.2.27 and I creat a script send. Look

<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(E_ALL);
require ‘/xxxxxx/PHPMailer-test/PHPMailerAutoload.php';
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();


$mail->Host       = "administrateur@xxxxxxx.com"; // SMTP server
//$mail->IsSMTP(); // telling the class to use SMTP

$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 2; //Alternative to above constant
// $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                         // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Username   = "administrateur@xxxxxxxxx.com";  // GMAIL username
$mail->Password   = "xx";            // GMAIL password
$mail->SMTPSecure = "ssl"; 
$mail->Port       = 587;                   // set the SMTP port for the GMAIL server

$mail->Host       = "ssl0.ovh.net";      // sets GMAIL as the SMTP server



$mail->From = "administrateur@xxxxxxx.com";

$mail->FromName = "test";

$mail->AddAddress ("xxxx@wanadoo.fr");

$mail->Subject    = "PHPMailer Test";

$mail->Body    = "Test"; // optional, comment out and test



if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent! ";
}
?> 

My script word but I would like to know how to have the sending log as below

enter image description here

How to display these logs? i tried with $mail->SMTPDebug = SMTP::DEBUG_SERVER; but is not work


Solution

  • First of all, you're using a very old version of PHPMailer. Get the latest.

    Your actual problem is very simple:

    //$mail->IsSMTP(); // telling the class to use SMTP
    

    You have no SMTP debug output because you not asked PHPMailer to use SMTP, so its using PHP's internal mail() function to send, and that generates no debug output.

    Just uncomment that line and you'll have debug output.