【问题标题】:Error in Smtp lib fileSMTP lib 文件中的错误
【发布时间】:2018-10-23 20:34:05
【问题描述】:

我想向注册用户发送确认邮件。我正在使用 php mailer 和 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 失败:不知道这样的主机。 (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...', '???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} 在 C:\wamp\www\Email Confirmation\lib\class.phpmailer.php 第 1093 行抛出

【问题讨论】:

  • 请解释您的代码行,以便其他用户了解其功能。谢谢!
  • AWS 至少部分阻止出站 SMTP。您好像被屏蔽了,所以请查看他们的文档。
  • @Synchro 你的意思是 AWS 文档?

标签: php email phpmailer


【解决方案1】:

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

【讨论】:

  • 我尝试在我的亚马逊服务器上测试这些文件。在我的亚马逊服务器中,我安装 wamp 服务器,然后运行这些文件。
  • 我将您的问题提交至此链接stackoverflow.com/questions/23497876/… 请检查 WAMP smtp 是否在您的服务器上运行。
  • 我也参考了链接,他们告诉使用 amazon SDk ,我也尝试了这种方式但仍然出现错误
【解决方案2】:

默认的 SMTP 端口是 587。尝试使用它。

【讨论】:

  • 默认 SMTP 端口是 25。默认 SMTP 提交端口是 587。
猜你喜欢
  • 2011-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-21
  • 1970-01-01
  • 2017-01-23
  • 2014-01-15
相关资源
最近更新 更多