The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cant send mails with PHPMailer

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

  1. telmark

    telmark Registered

    Joined:
    Jul 31, 2017
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    uruguay
    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.

    Code:
    And the PHP script returns:
        2017-07-30 21:46:54 SERVER -> CLIENT: 220-hosting.xxxx.cl 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 xxxx.com.ar
        2017-07-30 21:46:54 SERVER -> CLIENT: 250-hosting.xxxx.cl Hello vovstore.com.ar [xxx.xxx.xxx.xxx] 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 hosting.xxxx.cl 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:
    Code:
    <?php
    /**
     * 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
    date_default_timezone_set('Etc/UTC');
    
    require '../PHPMailerAutoload.php';
    
    //Create a new PHPMailer instance
    $mail = new PHPMailer;
    
    //Tell PHPMailer to use SMTP
    $mail->isSMTP();
    
    //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 = 'smtp.gmail.com';
    // use
    // $mail->Host = gethostbyname('smtp.gmail.com');
    // 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 = "xxxxxxx@xxxxxxx.com.ar";
    
    //Password to use for SMTP authentication
    $mail->Password = "xxxxxxx";
    
    //Set who the message is to be sent from
    $mail->setFrom('xxxxxx@gmail.com', 'First Last');
    
    //Set an alternative reply-to address
    $mail->addReplyTo('xxxxxxx@gmail.com', 'First Last');
    
    //Set who the message is to be sent to
    $mail->addAddress('xxxxxxx@gmail.com', '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
    $mail->addAttachment('images/phpmailer_mini.png');
    
    //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

    Joined:
    Aug 23, 2015
    Messages:
    542
    Likes Received:
    39
    Trophy Points:
    28
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hi,
    Do you have any custom firewall rules or applications that could block that port? If yes then try to disable it.
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,288
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

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

    Thank you.
     
Loading...

Share This Page