简体   繁体   中英

Email Verification using php and mysql : SMTP connect() failed for webmail

This is my php code for sending email verification link to user account

<?php
// php mailer code starts
    $mail = new PHPMailer(true);
    $mail->IsSMTP(); // telling the class to use SMTP

    $mail->SMTPDebug = 0;                     
    $mail->SMTPAuth = true;                  
    $mail->SMTPSecure = "ssl";               
    $mail->Host = "smtp.domain.in";     
    $mail->Port = 25;                   

    $mail->Username = 'admin@domain.in';
    $mail->Password = 'password';

    $mail->SetFrom('admin@domain.in', 'Admin');
    $mail->AddAddress($email);

    $mail->Subject = trim("Email Verifcation");
    $mail->MsgHTML($message);

    try {
      $mail->send();
      $msg = "An email has been sent for verfication.";
      $msgType = "success";
    } catch (Exception $ex) {
      $msg = $ex->getMessage();
      $msgType = "warning";
    }

?>

This code is working for gmail account like xyz@gmail.com . But its not working If I use webamail account like admin@domain.in .

I get 'SMTP connect() failed' error.

Can anyone please tell me where I am doing wrong in my code?

As always, the first thing you should do is read the docs . You should be able to figure out from this section that this will not work:

$mail->SMTPSecure = "ssl";
$mail->Port = 25;

That's asking for implicit TLS to work on a port that doesn't typically support it, so it will fail to connect. Do one of these instead:

$mail->SMTPSecure = 'ssl';
$mail->Port = 465;

or

$mail->SMTPSecure = 'tls';
$mail->Port = 587;

Other combinations are unlikely to work. You may have other issues too, but that one is fatal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM