Search code examples
phpemailphpmailer

Hide or not print messages from server


I have a script that sends mail from my server. This script is initiated after validation and sanitization of the details provided.The following is displayed on the website every time a mail is sent:

SMTP -> FROM SERVER:220-sg2plcpnl0187.prod.sin2.secureserver.net ESMTP Exim 4.87 #1 Thu, 01 Sep 2016 10:57:21 -0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. SMTP -> FROM SERVER: 250-sg2plcpnl0187.prod.sin2.secureserver.net Hello ip-166-62-27-191.ip.secureserver.net [166.62.27.191] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP SMTP -> FROM SERVER:250 OK SMTP -> FROM SERVER:250 Accepted SMTP -> FROM SERVER:354 Enter message, ending with "." on a line by itself SMTP -> FROM SERVER:250 OK id=1bfWEs-001FfR-22

I am using phpmailer. I looked into one of it's class files ( the file is class.smptp.php , which is written by phpmailer and included in the mail sending script) and found out that these messages are echoed from the script.

Commenting out each line from the file is a tedious task. I also do not want the user to see such a long and irrelevant message. What should be done?


Solution

  • Change this line (assuming you're using SMTP);

    $mail->SMTPDebug = 2;
    

    to

    $mail->SMTPDebug = 0;
    

    PHPMailer has a section of code where you set the type of debug messages as well as the output. For example:

    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 2;
    
    //Ask for HTML-friendly debug output
    $mail->Debugoutput = 'html';
    

    The first line sets the level of messages, the second states how to provide the output.