furquan

Well-Known Member
Jul 27, 2002
473
4
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][email protected][/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][email protected][/EMAIL]', 'Mailer');
$mail->addAddress('[EMAIL][email protected][/EMAIL]'); // Name is optional
//$mail->addReplyTo('[EMAIL][email protected][/EMAIL]', 'Information');
//$mail->addCC('*******@gmail.com');
//$mail->addBCC('[EMAIL][email protected][/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
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,228
463
$mail->Port = 587; // TCP port to connect to
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.
 

furquan

Well-Known Member
Jul 27, 2002
473
4
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,
 

furquan

Well-Known Member
Jul 27, 2002
473
4
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
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,228
463
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.