php - 关于在 php 中发送邮件的 fsockopen() 错误

标签 php ssl smtp xampp fsockopen

我想在用户注册后向用户发送确认电子邮件。我正在使用 xampp。当我运行我的 php 文件时,它返回以下错误:

    Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in C:\xampp\htdocs\class.smtp.php on line 122

    Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in C:\xampp\htdocs\class.smtp.php on line 122
    Message has not been sent. 

我的 php 文件中的相关部分:

try
    {
        require("class.phpmailer.php");
        $mail = new PHPMailer();   
        $mail->IsSMTP();
        $mail->Mailer = "smtp";
        $mail->SMTPSecure = "ssl"; 
        $mail->Host = "ssl://smtp.gmail.com";
        $mail->Port = 465;
        $mail->SMTPAuth = true;
        $mail->CharSet="utf-8";
        $mail->Username = "user@gmail.com";
        $mail->Password = "password";
        $mail->From     = "user@gmail.com";
        $mail->FromName="DBE Yazılım";
        $mail->AddAddress($_POST['UserMail']); 
        $mail->Subject  = "Registration Information";
        $mail->Body     = "Hello your password is " . $userpass;
        //$mail->AddAttachment($path);
        $mail->Send();
        if($mail->Send())
            echo 'Message has been sent.';
        else
            echo 'Message has not been sent.';
    }
    catch(Exception $e)
    {
        echo 'hata'.$e->getMessage();
    }

我看过论坛,这个错误通常是关于 ssl 的。他们说 extension=php_openssl.dll 必须添加到 php.ini 中。我添加了这部分,但没有任何改变。这是关于xampp的吗?

提前致谢。

最佳答案

如您在错误消息中所见

unable to connect to ssl://ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in C:\xampp\htdocs\class.smtp.php on line 122

ssl:// 太多了

$mail->Host = "smtp.gmail.com"; // instead of ssl://smtp.gmail.com

通常,如果您看到术语“主机”,这实际上意味着“主机”而不是 url

关于php - 关于在 php 中发送邮件的 fsockopen() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11540333/

相关文章:

c# - 在不同的 smtp 端口上发送带有附件的电子邮件

php - 使用 GROUP BY 和 count 优化 MySQL 查询结果中的顺序

php - 将 mysql 转换为 PDO 的问题

amazon-web-services - AWS 为负载均衡器请求 ACM HTTPS 证书

c# - 在 mvc 应用程序中发送电子邮件时遇到问题

PHP 通过随机电子邮件帐户发送电子邮件

PHP 通过多维数组的值更新表

php - 多维数组转 CSV

java - 试图理解 Java 中的 SSL 证书

php - 子域不适用于 https