0

I'm Trying to send email via php by using php mailer, but it's showing SMTP connect() failed. here is my code. can't find out what is problem in that. if somebody help to track error it will be very helpful for me.

$mail = new PHPMailer;
$mail->isSMTP();                                   // Set mailer to use SMTP
$mail->Host = 'dds.uemtv.com';                    // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                            // Enable SMTP authentication
$mail->Username = 'no-reply@domain.pk';          // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls';                         // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                 // TCP port to connect to

$mail->setFrom('no-reply@domain.pk', 'domain');
$mail->addReplyTo($email, '$name');
$mail->addAddress($email);   // Add a recipient
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

$mail->isHTML(true);  // Set email format to HTML

$bodyContent = '<h1>Your Registration Completed. </h1>'
$mail->Subject = 'Verify Account- Rozgar';
$mail->Body    = $bodyContent;
if(!$mail->send()) {
    echo $data->msg = $mail->ErrorInfo;
} else {
    // echo 'Message has been sent';
     echo $data->msg="Please Verify Your Email Address";
}
Mantas Čekanauskas
  • 2,218
  • 6
  • 23
  • 43

1 Answers1

0

Don't use random settings and hope it works. SMTPSecure = 'tls' will not work with Port = 465. Set Port = 587 for explicit TLS.

In general, use the latest version, base your code on the examples provided with PHPMailer, and read the troubleshooting guide that the error messages point you to.

Synchro
  • 35,538
  • 15
  • 81
  • 104
  • So read [the guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting), do what it says. If that doesn't fix it, add your findings to your question. – Synchro Jun 07 '17 at 08:54