Keerthi
Keerthi

Reputation: 11

Error in Smtp lib file

I want to send conformation mail to registered user. I am using php mailer and smtp lib class file to send mail to registered user.

 if(isset($_POST['submit']))
    {
        require "dbc.php";

        $username = $_POST['username'];
        $email = ($_POST['email'];
        $password = $_POST['password'];

        $enc_password = md5($password);

        if($username && $email && $password)
        {
            $confirmcode = rand();
            $query = mysql_query("INSERT INTO `tutorial` VALUES('','$username','$enc_password','$email','0','$confirmcode')");

            $message =
            "
            Confirm Your Email
            Click the link below to verify your account
            http://www.example.com/emailconfirm.php?username=$username&code=$confirmcode
            ";
             require_once($_SERVER['DOCUMENT_ROOT'].'/lib/class.phpmailer.php');
                require_once($_SERVER['DOCUMENT_ROOT'].'/lib/class.smtp.php');
                $mail = new PHPMailer(true);
                $from = "[email protected]";
                     $mail->IsSMTP();
             //$mail->SMTPSecure = 'ssl'; 
             $mail->SMTPDebug = 1;
             $mail->Host = 'smtp.us-east-1.amazonaws.com';
             $mail->SMTPAuth = true;
             $mail->Username = '[email protected]';
             $mail->Password = '******';
             $mail->Sender = $from;
             $mail->From = $from;
             $mail->AddReplyTo($email);
             $mail->FromName ="Mail";
             $mail->AddAddress($email);
             $mail->Port = 25;
        $mail->IsHTML(true);
             $mail->Subject = $subject;
             $mail->Body = $message;
             $mail->WordWrap = 50;
             $mail->Send();

            echo "Registration Complete! Please confirm your email address";
        }
    }

But I got this error.

SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) Fatal error: Uncaught exception 'phpmailerException' with message 'SMTP Error: Could not connect to SMTP host.' in C:\wamp\www\Email Confirmation\lib\class.phpmailer.php:1093 Stack trace: #0 C:\wamp\www\Email Confirmation\lib\class.phpmailer.php(971): PHPMailer->SmtpConnect() #1 C:\wamp\www\Email Confirmation\lib\class.phpmailer.php(845): PHPMailer->SmtpSend('Date: Mon, 14 M...', '???Confirm Your...') #2 C:\wamp\www\Email Confirmation\lib\class.phpmailer.php(763): PHPMailer->PostSend() #3 C:\wamp\www\Email Confirmation\register.php(61): PHPMailer->Send() #4 {main} thrown in C:\wamp\www\Email Confirmation\lib\class.phpmailer.php on line 1093

Upvotes: 1

Views: 102

Answers (2)

Omar Abu Omar
Omar Abu Omar

Reputation: 62

I think you're trying to send an email on your local machine, it will not work with WAMP, Try it on your server,

Upvotes: 1

Hariprasad S H
Hariprasad S H

Reputation: 63

The default SMTP port is 587. Try using that.

Upvotes: 0

Related Questions