Smtp lib文件出错

时间:2018-05-14 08:27:04

标签: php email phpmailer

我想向注册用户发送确认邮件。我使用php邮件程序和smtp lib类文件向注册用户发送邮件。

 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";
        }
    }

但我收到了这个错误。

  

SMTP - >错误:无法连接到服务器:php_network_getaddresses:getaddrinfo failed:没有这样的主机已知。 (0)   致命错误:未捕获的异常' phpmailerException'消息' SMTP错误:无法连接到SMTP主机。'在C:\ wamp \ www \ Email Confirmation \ lib \ class.phpmailer.php:1093堆栈跟踪:#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 ...', ' ???确认你的...')#2 C:\ wamp \ www \ Email确认\ lib \ class.phpmailer.php(763):PHPMailer-> PostSend()#3 C :\ wamp \ www \ Email确认\ register.php(61):PHPMailer->发送()#4 {main}在1093行的C:\ wamp \ www \ Email Confirmation \ lib \ class.phpmailer.php中引发

2 个答案:

答案 0 :(得分:0)

默认SMTP端口为587.尝试使用它。

答案 1 :(得分:0)

我认为您正在尝试在本地计算机上发送电子邮件,但它不适用于WAMP,请在您的服务器上试用,