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!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHPMailer Issue

Discussion in 'E-mail Discussions' started by furquan, Jul 10, 2017.

  1. furquan

    furquan Well-Known Member

    Joined:
    Jul 27, 2002
    Messages:
    461
    Likes Received:
    3
    Trophy Points:
    168
    Hello Everyone,

    Can somebody, Please look into my mailing script below and let me know what is wrong with it for cpanel to throw various different errors like :-

    CLIENT: 220 , SMTP Error: Could not connect to SMTP host, SMTP connect() failed.

    The script refuses to work :(, What wrong am i doing here, Please suggest !


    I created the script:

    example.com/razvoj/web_stranice/nullboxv1/funkcije/email2.php

    PHP SCRIPT:
    Code:
    <?php
    require'/home/someuser/public_html/razvoj/web_stranice/nullboxv1/funkcije/phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;
    $mail->SMTPDebug =3; // Enable verbose debug output
    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'localhost'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = '[EMAIL]ME@mydomain.com[/EMAIL]'; // SMTP username
    $mail->Password = 'somepassword'; // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption, ssl also accepted
    $mail->Port = 587; // TCP port to connect to
    $mail->setFrom('[EMAIL]ME@mydomain.com[/EMAIL]', 'Mailer');
    $mail->addAddress('[EMAIL]SOMEGMAILID@gmail.com[/EMAIL]'); // Name is optional
    //$mail->addReplyTo('[EMAIL]info@hostname.com[/EMAIL]', 'Information');
    //$mail->addCC('*******@gmail.com');
    //$mail->addBCC('[EMAIL]bcc@example.com[/EMAIL]');
    //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
    $mail->isHTML(true); // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    exit();
    } else {
    echo 'Message has been sent';
    }
    ?>
    
    Appreciate your time guys,

    Thank you
     
    #1 furquan, Jul 10, 2017
    Last edited by a moderator: Jul 11, 2017
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,419
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Have you tried switching to port 25 to see if you encounter the same error message? Also, I do see that debug mode is enabled. Is there any additional output you see when testing the script other than the error message you provided?

    Thank you.
     
  3. furquan

    furquan Well-Known Member

    Joined:
    Jul 27, 2002
    Messages:
    461
    Likes Received:
    3
    Trophy Points:
    168
    Thank you so very much for your reply Michael,

    I shall have this checked out tomorrow when i reach office and will get back to you on this.

    Highly appreciate your response.

    Thank you,
     
  4. furquan

    furquan Well-Known Member

    Joined:
    Jul 27, 2002
    Messages:
    461
    Likes Received:
    3
    Trophy Points:
    168
    Hello Michael,

    I went ahead and changed the port number to 25 and also changed the debug value to 0, and now this is what i see on the screen after i call the script in the browser :-

    Message could not be sent.Mailer Error: SMTP connect() failed. Troubleshooting · PHPMailer/PHPMailer Wiki · GitHub

    What next can be done, Please suggest.

    Thank you
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,419
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    It's actually more helpful to set the debug mode to "3" to ensure more verbose log details are provided. Do you have any firewall rules blocking local access to port 25?

    Thank you.
     
Loading...

Share This Page