1

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 = "support@example.com";
                     $mail->IsSMTP();
             //$mail->SMTPSecure = 'ssl'; 
             $mail->SMTPDebug = 1;
             $mail->Host = 'smtp.us-east-1.amazonaws.com';
             $mail->SMTPAuth = true;
             $mail->Username = 'support@example.com';
             $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

Aneesh R S
  • 3,807
  • 4
  • 23
  • 35
Keerthi
  • 11
  • 1

2 Answers2

1

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

  • I tried test on these files on my amazon server.In my amazon server I install wamp server and then run these files. – Keerthi May 15 '18 at 06:44
  • I refer your problem to this link https://stackoverflow.com/questions/23497876/using-phpmailer-and-amazon-ses please check if WAMP smtp is working on your server. – Omar Abu Omar May 15 '18 at 08:28
  • I also refer the link, they told to use amazon SDk , I also tried the way but still I got error – Keerthi May 15 '18 at 14:21
0

The default SMTP port is 587. Try using that.