Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Cant send mails with PHPMailer

Discussion in 'E-mail Discussion' started by telmark, Jul 31, 2017.

  1. telmark

    telmark Registered

    Jul 31, 2017
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator
    I can not send mails (I want to send them directly from Gmail, not with the mail () function), I'm trying the PHPMailer library and when I run it from a URL It does not work, it disconnects me from the server in the middle of the connection. If I do from SSH, with the root user, all right, send the mails correctly.
    The option: whm > security center > SMTP Restrictions is Disable.
    Now if I run from the browser that same, it does not work:
    In: /var/log/apache2/error_log does not register errors.

    And the PHP script returns:
        2017-07-30 21:46:54 SERVER -> CLIENT: ESMTP Exim 4.89 # 1 Sun, 30 Jul 2017 17:46:54 -0400 220-We do not authorize the use of this system To transport unsolicited, 220 and / or bulk email.
        2017-07-30 21:46:54 CLIENT -> SERVER: EHLO
        2017-07-30 21:46:54 SERVER -> CLIENT: Hello [] 250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
        2017-07-30 21:46:54 CLIENT -> SERVER: STARTTLS
        2017-07-30 21:46:54 SERVER -> CLIENT: 220 TLS go ahead
        SMTP Error: Could not connect to SMTP host.
        2017-07-30 21:46:54 CLIENT -> SERVER: QUIT
        2017-07-30 21:46:54 SERVER -> CLIENT: 221 closing connection
        SMTP connect () failed. Troubleshooting · PHPMailer/PHPMailer Wiki · GitHub
        Mailer Error: SMTP connect () failed. Troubleshooting · PHPMailer/PHPMailer Wiki · GitHub
    It seems that you are just starting to send the mail, close the connection. What can be the problem?

    The code of the script is the follow:
     * This example shows settings to use when sending via Google's Gmail servers.
    //SMTP needs accurate times, and the PHP time zone MUST be set
    //This should be done in your php.ini, but this is how to do it if you don't have access to that
    require '../PHPMailerAutoload.php';
    //Create a new PHPMailer instance
    $mail = new PHPMailer;
    //Tell PHPMailer to use SMTP
    //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';
    //Set the hostname of the mail server
    $mail->Host = '';
    // use
    // $mail->Host = gethostbyname('');
    // if your network does not support SMTP over IPv6
    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
    $mail->Port = 587;
    //Set the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'tls';
    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;
    //Username to use for SMTP authentication - use full email address for gmail
    $mail->Username = "";
    //Password to use for SMTP authentication
    $mail->Password = "xxxxxxx";
    //Set who the message is to be sent from
    $mail->setFrom('', 'First Last');
    //Set an alternative reply-to address
    $mail->addReplyTo('', 'First Last');
    //Set who the message is to be sent to
    $mail->addAddress('', 'John Doe');
    //Set the subject line
    $mail->Subject = 'PHPMailer GMail SMTP test';
    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
    //Replace the plain text body with one created manually
    $mail->AltBody = 'This is a plain-text message body';
    //Attach an image file
    //send the message, check for errors
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    #1 telmark, Jul 31, 2017
    Last edited by a moderator: Jul 31, 2017
  2. SysSachin

    SysSachin Well-Known Member

    Aug 23, 2015
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator
    Do you have any custom firewall rules or applications that could block that port? If yes then try to disable it.
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Apr 11, 2011
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator

    Are you also using the CSF firewall? If so, check to see if the "SMTP_BLOCK" setting is enabled.

    Thank you.
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice