user4569202
user4569202

Reputation:

SMTP ERROR: unable to connect

i am getting this error kindly help me

2015-03-06 10:43:16 SMTP ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it. (10061) 2015-03-06 10:43:16 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

my code is
<?php
require 'classes/class.phpmailer.php';
require 'classes/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->SMTPDebug = 1;                              // 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 = 'root';                            // SMTP username
$mail->Password = '';                                // SMTP password
$mail->SMTPSecure = 'ssl';                           // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                   // TCP port to connect to

$mail->From = '[email protected]';
$mail->FromName = 'usman';
$mail->addAddress('[email protected]', 'usmanxxx');     // Add a recipient
$mail->addAddress('[email protected]');                // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');

//$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 = 'subject is send email';
$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;
} else {
    echo 'Message has been sent';
}

Upvotes: 1

Views: 8071

Answers (1)

Didit Dwianto
Didit Dwianto

Reputation: 326

some while ago I also encountered this problem. The server admin is also not very helpful, but from what i have already done, this is the thing that must be checked :

  1. Host, this is the address of the SMTP server, if you want to connect to some server, i believe this is not localhost. Example : mail.mycompany.com
  2. SMTPsecure, there are some method for securing transmission, you can test using SSL or TLS or STARTTLS
  3. Port, test for the correct port. Commonly it uses port 465, but it can be other. For example STARTTLS uses port 587.
  4. You can try to analyze the output debug message regarding your error.

Please correct me if i'm wrong.

Upvotes: 2

Related Questions